# 2016 US Open Bronze Problem 1

For this problem, my code is failing on 4/10 test cases, 5 7 9, and 10.

This is my code

``````#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);
}
}

int main(){
//	setIO("diamond");
//	making variables
int n, k, t = 0, tt= 0;
cin >> n >> k;
int d[n];
vector<int> allowed;
//	getting all diamond sizes and adding to an array
for(int i = 0; i < n; i++){
cin >> d[i];
}
//  if there is only one element output 1
if(n == 1){
cout << 1 << "\n";
return 0;
}
//	start looping through all the diamond sizes
for(int i = 0; i < n; i++){
// adds whichever element i is on which will be used as the base for testing other values
allowed.push_back(d[i]);
// starts at values greater than i to test it with all other values
for(int j = i + 1; j < n; j++){
int x = 0;
// starts looping through all the values inside allowed
for(int o = 1; o <= allowed.size(); o++){
// if the element is within k of the element o is on add one to x
if(abs(d[j] - allowed[o - 1]) <= k){
x += 1;
}
// if d[j] was within k of all the elements that allowed had then add it to allowed and break
if(o == (allowed.size())){
if(x == (allowed.size())){
allowed.push_back(d[j]);
break;
}
}
}
}
// tt will be set to the amount of values that are withink k of eachother starting at i and if it's greater than t, set t to tt
tt = allowed.size();
t = max(t, tt);
allowed.clear();
}
// if there were no values within k of eachother just display one diamond
if(t != 0){
cout << t << "\n";
}else{
cout << 1 << "\n";
}
return 0;
}
``````

I have already tried everything in the debugging module (https://usaco.guide/general/debugging-general?lang=cpp)

add “sort(d, d + n);” to sort the diamonds from smallest to largest