In competitive programming I used Integer instead of int but it got me TLE error Can you tell me why? Basically i have to just sort the array and traverse it. my code is here
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int scene = sc.nextInt();
int j=1;
while(j<=scene)
{
int need = sc.nextInt();
int frnds = sc.nextInt();
int arr[] = new int[frnds];
for(int i=0;i<frnds;i++)
arr[i] = sc.nextInt();
Arrays.sort(arr);
int count =0;
System.out.println("Scenario #"+j+":");
for(int i=frnds-1;i>=0;i--)
{
count++;
need -= arr[i];
if(need<=0) {
System.out.println(count);
break;
}
}
if(need>0)
System.out.println("impossible");
System.out.println();
j++;
}
}
}