-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJ11659.java
More file actions
27 lines (24 loc) · 758 Bytes
/
Copy pathJ11659.java
File metadata and controls
27 lines (24 loc) · 758 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
package TIL;
import java.util.Scanner;
public class J11659 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int index = scanner.nextInt();
int n = scanner.nextInt();
int[] array = new int[index];
int[] array2 = new int[index+1];
int sum = 0;
int result = 0;
for(int i = 0; i <array.length; i++) {
array[i] = scanner.nextInt();
sum += array[i];
array2[i+1] = sum;
}
for(int i = 0; i < n; i++){
int startNum = scanner.nextInt();
int endNum = scanner.nextInt();
result = array2[endNum] - array2[startNum-1];
System.out.println(result);
}
}
}