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 :)