Runtime error on test 3 on Codeforces Round #366 Div 2 — Thor

Revision en1, by jsaita96, 2016-08-08 18:09:15

704A - Thor Hello everyone, I've just started competitive programming and love this site! So, I took part in Round #366, and I am getting a Runtime error on test 3 in Problem Thor. I tried to find it, but I couldn't find it. So, if anyone can point out what is causing the Runtime error in the code below:-

public class Thor {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line1 = br.readLine();
        StringTokenizer tokenizer = new StringTokenizer(line1," ");
        int n = Integer.parseInt(tokenizer.nextToken());
        int q = Integer.parseInt(tokenizer.nextToken());
        
        int[] notifs = new int[n+1];
        long[] res = new long[q+1];
        long sum=0L;
        
        for(int i=0;i<q;i++){
            String ip = br.readLine();
            StringTokenizer token = new StringTokenizer(ip," ");
            int type = Integer.parseInt(token.nextToken());
            int var2 = Integer.parseInt(token.nextToken());
            switch(type){
                case 1:
                    notifs[var2]++;
                    sum++;
                    break;
                case 2:
                    int r = notifs[var2];
                    sum-=Long.parseLong(String.valueOf(r));
                    notifs[var2]=0;
                    break;
                case 3:
                    int rem = var2;
                    int j=1;
                    while(rem!=0){
                        if(notifs[j]>=rem){
                            notifs[j]-=rem;
                            rem-=var2;
                            break;
                        }else{
                            rem-=notifs[j];
                            notifs[j]=0;
                        }
                        j++;
                    }
                    sum-=Long.parseLong(String.valueOf(var2));
            }
            res[i]=sum;
        }
        
        for(int i=0;i<q;i++){
            System.out.println(res[i]);
        }
    }
}

Thanks :)

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English jsaita96 2016-08-08 18:09:15 2227 Initial revision (published)