https://www.acmicpc.net/problem/11659
import java.util.Scanner;
public class B11659 {
//S[i] = S[i-1] + A[i]
//S[j] - S[i-1] i에서 j까지 구간 합
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int M = sc.nextInt();
int S[]=new int[N+1];
//구간합 만들기
S[0]=0;
for(int i=1;i<=N;i++){
S[i]=S[i-1]+sc.nextInt();
}
for(int i=0;i<M;i++){
int f=sc.nextInt();
int l=sc.nextInt();
System.out.println(S[l]-S[f-1]);
}
}
}
'JAVA' 카테고리의 다른 글
[백준/자바] 1253번: 좋다 (0) | 2023.07.11 |
---|---|
[백준/자바] 1940번: 주몽 (0) | 2023.07.11 |
[백준/자바] 16395번: 파스칼의 삼각형 (0) | 2023.07.04 |
[백준] 1010번: 다리 놓기 (0) | 2023.07.04 |
[백준] 17202번 핸드폰 번호 궁합 (0) | 2023.06.20 |
댓글