返回列表 發帖
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;


  4. public class Ch01 {
  5.         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  6.         String str[];
  7.         int n,m,data[],res[];
  8.     Ch01() throws Exception
  9.     {
  10.       while((str=br.readLine().split(" "))!=null)
  11.       {
  12.               n=Integer.parseInt(str[0]);
  13.               m=Integer.parseInt(str[1]);
  14.               data=new int[n+1];
  15.               res=new int[n+1];
  16.               str=br.readLine().split(" ");
  17.               for(int i=1; i<=n; i++)
  18.               {
  19.                       int t=Integer.parseInt(str[i-1]);
  20.                       res[i]=res[i-1]+t;
  21.               }
  22.               for(int i=0; i<m; i++)
  23.               {
  24.                       str=br.readLine().split(" ");
  25.                       System.out.println(res[Integer.parseInt(str[1])]-(res[Integer.parseInt(str[0])-1]));                 
  26.               }
  27.               
  28.       }
  29.     }
  30.         public static void main(String[] args) throws Exception {
  31.                 new Ch01();

  32.         }

  33. }
複製代碼

TOP

返回列表