Debugging help for this bronze problem

Problem Info

2016 US Open Bronze: 1. Diamond Collector

My Work

#include <bits/stdc++.h>
using namespace std;

int main() {
	freopen("diamond.in", "r", stdin);
	freopen("diamond.out", "w", stdout);
	int N, K; cin >> N >> K;
	int sizes[N];
	for(int c: sizes){
		cin >> c;
	}
	int maxi = -100000;
	int total = 0;
	for(int i = 0; i < N; i++){
		total = 0;
		int must = sizes[i];
		for(int j = 0; j < N; j++){
			if(abs(sizes[j]-must) <= K){
				total++;
			}
		}
		maxi = max(maxi, total);
	}
	cout << maxi << endl;
}

What I’ve Tried

what i do is I choose one diamond that I must include, and then check to see how many diamonds are <= k sizes away and then I do that for every iteration of diamond I must include and keep the maximym

bump bump

according to the editorial, you should brute force the smallest diamond in the case. Merely check all diamonds larger (EDIT: that fit)

Example:

// do your inputs and stuff

int maximum = 0;
for (auto i : a) {
     int current = 0;
     for (auto j : a) {
          if (j >= i && i + k >= j) current++;
     }
     maximum = max(maximum, current);
}

@Juan_Belza_Garcia