TLE in Java

Правка en1, от rgoewedky, 2020-07-15 07:11:56

I am getting TLE in Range Sum Query 1 of CSES problem set. Although, I pre-compute prefix sum and time complexity is also under constraints. Here is my code . Please Help. THANKS in ADVANCE

import java.io.*;
import java.util.*;

public class Main{      
	public static void main(String[] args)throws Exception{
         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
         
          StringTokenizer st;
         
        st=new StringTokenizer(br.readLine()); 
        int n=Integer.parseInt(st.nextToken());
        int q=Integer.parseInt(st.nextToken());

        long prefix[]=new long[n+1];
        prefix[0]=0;

        st=new StringTokenizer(br.readLine()); 
        for (int i=1;i<=n;i++) {
          int x=Integer.parseInt(st.nextToken());
          prefix[i]=prefix[i-1]+x;
        }

    while(q-->0){
      
       st=new StringTokenizer(br.readLine()); 
      int l=Integer.parseInt(st.nextToken());
      int r=Integer.parseInt(st.nextToken());
       System.out.println(prefix[r]-prefix[l-1]);
	}
}
}


История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский rgoewedky 2020-07-15 07:11:56 1118 Initial revision (published)