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