-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBAEKJOON_11659
More file actions
32 lines (28 loc) · 1.05 KB
/
BAEKJOON_11659
File metadata and controls
32 lines (28 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw =new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
int[] arr = new int[N+1];
arr[0] = 0;
StringTokenizer st2 = new StringTokenizer(br.readLine());
for(int i=1; i<N+1; i++){
arr[i] = arr[i-1]+Integer.parseInt(st2.nextToken());
}
int sum=0;
for(int i=0; i<M; i++){
StringTokenizer st3= new StringTokenizer(br.readLine());
int a = Integer.parseInt(st3.nextToken());
int b= Integer.parseInt(st3.nextToken());
sum =arr[b]-arr[a-1];
bw.write(String.valueOf(sum));
bw.newLine();
bw.flush();
}
bw.close();
}
}