-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJ11659_4.java
More file actions
29 lines (25 loc) · 914 Bytes
/
Copy pathJ11659_4.java
File metadata and controls
29 lines (25 loc) · 914 Bytes
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
package TIL;
import java.io.*;
public class J11659_4 {
static int n, m;
static int[] box, sumBox;
public static void main(String[] args) throws IOException {
BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
String[] input = buffer.readLine().split(" ");
n = Integer.parseInt(input[0]);
m = Integer.parseInt(input[1]);
box = new int[n+1];
sumBox = new int[n+1];
input = buffer.readLine().split(" ");
for(int i = 1 ; i <= n; i++){
box[i] = Integer.parseInt(input[i-1]);
sumBox[i] = sumBox[i-1] + box[i];
}
for(int i = 0 ; i < m; i++){
input = buffer.readLine().split(" ");
int start = Integer.parseInt(input[0]);
int end = Integer.parseInt(input[1]);
System.out.println(sumBox[end]- sumBox[start-1]);
}
}
}