返回列表 發帖
  1. package a693;

  2. import java.io.BufferedReader;
  3. import java.io.IOException;
  4. import java.io.InputStreamReader;

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

  31.         int getSum(int l, int r) {
  32.                 return sum[r]-sum[l-1];
  33.         }
  34.         public static void main(String[] args) throws Exception {
  35.                 new a693();
  36.         }

  37. }
複製代碼

TOP

返回列表