# 2016 US Open Bronze Bronze Problem 1. Diamond Collector

For USACO 2016 US Open Contest, Bronze Problem 1. Diamond Collector, my code is failing on some test cases

http://www.usaco.org/index.php?page=viewproblem2&cpid=639

#include <bits/stdc++.h>

using namespace std;

void setIO(string name = “”){
ios_base::sync_with_stdio(0); cin.tie(0);
if(name.size()){
freopen((name+".in").c_str(), “r”, stdin);
freopen((name+".out").c_str(), “w”, stdout);
}
}

``````	setIO("diamond");
int n, k, t = 0, tt= 0;
cin >> n >> k;
int d[n];
vector<int> allowed;
for(int i = 0; i < n; i++){
cin >> d[i];
}
if(n == 1){
cout << 1 << "\n";
return 0;
}
for(int i = 0; i < n; i++){
allowed.push_back(d[i]);
for(int j = i + 1; j < n; j++){
int x = 0;
for(int o = 1; o <= allowed.size(); o++){
if(abs(d[j] - allowed[o - 1]) <= k){
x += 1;
}
if(o == (allowed.size())){
if(x == (allowed.size())){
allowed.push_back(d[j]);
tt = allowed.size();
t = max(t, tt);
break;
}
}
}
}
allowed.clear();
}

cout << t << "\n";
return 0;
}```

I looked at the internal solution on the USACO module, and I saw that they sorted the vector with all the values, but I don't know why mine is failing for some test cases.``````
1 Like