i was trying to do the E. Boxers problem in java my idea was to use a treeSet and put the boxer weight in the set and if his weight is already present in the tree i would try to put his (weight + 1) or his (weight — 1) using the treeSet contains method to know if i_th weight is already in the team of boxers
i did many custom tests on my code and they always give a correct answer but in submtion i get a wrong answer on test three and i couldnt find a semantic error in my code
could someone take a look at it and tell me whats wrong because i have been stuck in this problem for a while
the code :-
import java.util.Scanner; import java.util.TreeSet;
public class boxers {
public static void main(String[] args) {
// TODO Auto-generated method stub
int n, boxer, k;
Scanner scan = new Scanner(System.in);
TreeSet<Integer> set = new TreeSet<Integer>();
n = scan.nextInt();
k = 0;
for (int i = 0; i < n; i++) {
boxer = scan.nextInt();
if (!set.contains(boxer)) {
set.add(boxer);
k++;
}
else if (!set.contains(boxer + 1)) {
set.add(boxer + 1); k++;
}
else if (boxer > 1 && !(set.contains(boxer - 1))) {
set.add(boxer - 1);
k++;
}
}
System.out.println(k);
}
}



