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