https://www.acmicpc.net/problem/2003
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
st = new StringTokenizer(br.readLine());
int [] number = new int [N];
int count = 0;
for(int i=0; i<N; i++){
number[i] = Integer.parseInt(st.nextToken());
}
int start = 0;
int end = 0;
int hap = 0;
while(true){
if(hap >= M){
hap -= number[start++];
} else if (end == N) break;
else{
hap += number[end++];
}
if(hap == M)
count++;
}
System.out.println(count);
}
}
'코딩테스트 > 백준' 카테고리의 다른 글
[백준-자바] 7795번 먹을 것인가 먹힐 것인가 / 2022.06.04 (0) | 2022.06.04 |
---|---|
[백준-자바] 11728번 배열 합치기 / 2022.06.04 (0) | 2022.06.04 |
[백준-자바] 1874번 스택 수열 / 2022.05.26 (0) | 2022.05.26 |
[백준-자바] 17608번 막대기 / 2022.05.24 (0) | 2022.05.24 |
[백준-자바] 1253번 좋다 / 2022.05.23 (0) | 2022.05.23 |