-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ11659.java
More file actions
41 lines (33 loc) · 749 Bytes
/
Copy pathBOJ11659.java
File metadata and controls
41 lines (33 loc) · 749 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
30
31
32
33
34
35
36
37
38
39
40
41
package day1.array;
import java.util.Scanner;
public class BOJ11659 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int N=sc.nextInt();
int M=sc.nextInt();
int[] arr=new int[N+1];
int[] s=new int[N+1];
for (int i = 1; i <= N; i++) {
arr[i] =sc.nextInt();
s[i]=s[i-1]+arr[i];
}
for (int i = 0; i < M; i++) {
int start=sc.nextInt();
int end=sc.nextInt();
System.out.println(s[end]-s[start-1]);
}
// for (int i = 0; i < N; i++) {
// arr[i]=sc.nextInt();
// }
//
// for (int i = 0; i < M; i++) {
// int cnt=0;
// int a=sc.nextInt();
// int b=sc.nextInt();
// for (int j = a-1; j < b; j++) {
// cnt+=arr[j];
// }
// System.out.println(cnt);
// }
}
}