
-Code
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();
long[] sumList = new long[N + 1];
// 구간 합 리스트 만들기
for (int i = 1; i < N + 1; i++) {
long num = sc.nextLong();
sumList[i] = sumList[i - 1] + num;
}
// 입력 받기 및 출력
for (int i = 0; i < M; i++) {
int start = sc.nextInt();
int end = sc.nextInt();
System.out.println(sumList[end] - sumList[start - 1]);
}
}
}'Beakjoon&프로그래머스 > Java' 카테고리의 다른 글
| [백준/Java] 1940번 주몽 (0) | 2025.09.19 |
|---|---|
| [백준/Java] 2018번 수들의 합 5 (0) | 2025.09.18 |
| [LeetCode/Java] 9. Palindrome Number (0) | 2025.06.16 |
| [LeetCode/Java] 383. Ransom Note (1) | 2025.06.10 |
| [LeetCode/Java] 876. Middle of the Linked List (0) | 2025.06.10 |