Codeforces Educational Codeforces Round 61 Div2 B

question link- https://codeforces.com/problemset/problem/1132/B

can anyone please help me why my code is giving TLE?

import java.util.*;
public class Main{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int size=sc.nextInt();
        long[] arr=new long[size];
        long sum=0;
        for(int i=0;i<size;i++){
            arr[i]=sc.nextLong(); 
            sum+=arr[i];
        }
        Arrays.sort(arr);
        int queries=sc.nextInt();
        while(queries-->0){
            int num=sc.nextInt();
            System.out.println(sum-arr[size-num]);
        }
        
    }
    
}
1 Like

Try using Fast I/O

Check this:
https://codeforces.com/contest/1132/submission/94496153 (Without Fast I/O)
https://codeforces.com/contest/1132/submission/94496830 (With Fast I/O)

1 Like

yeah, Thanks.