How am i getting TLE and AC for the exact same code?

public static void main (String[] args) throws java.lang.Exception
{
Reader sc = new Reader();
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
int x = sc.nextInt();
HashSet set = new HashSet<>();
for (int i = 0; i < n; i++) {
set.add(sc.nextInt());
}
if(n-x >= set.size()){
System.out.println(set.size());
} else {
System.out.println(n-x);
}
}
}
//I got TLE at the time of contest but after completion of contest the same code got accepted with AC (100 %)