Problem Info
Diamond Collector
“USACO”
My Work
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e9);
int main(){
ifstream fin("diamond.in");
ofstream fout("diamond.out");
int N, K;
fin >> N >> K;
vector<int> vec(N);
for (int &i : vec) fin >> i;
int best = 0;
for (int i = 0; i < vec.size(); i++) {
int tmp = 0;
int mi = vec[i];
int ma = vec[i];
for (int j = 0; j < vec.size(); j++) {
if (abs(vec[j] - mi) <= K && abs(vec[j] - ma) <= K) {
tmp++;
mi = min(mi, vec[j]);
ma = max(ma, vec[j]);
}
}
best = max(best, tmp);
}
fout << best;
return 0;
}
What I’ve Tried
I passed all test cases with standard sol. But this one somehow failed 3 test cases. Anyone know why that is? Thank you! I feel like it’s supposed to work but it’s obviously failing some edge cases.