https://www.acmicpc.net/problem/2003
package javaTest;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class BOJ_2003 {
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = null;
int start = 0;
int end = 0;
int sum = 0;
int count = 0;
st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
int[] numbers = new int[N];
st = new StringTokenizer(br.readLine());
for(int i=0; i<N; i++) {
numbers[i] = Integer.parseInt(st.nextToken());
}
while(start < N) {
//합이 M보다 크거나, end point가 끝에 다다른 경우 start 위치를 한칸 옮겨준다
if(sum >= M || end == N){
sum -= numbers[start++];
}else {//합이 M과 같거나, 작을때 end point를 한칸 옮겨준다
sum += numbers[end++];
}
if(sum == M) {
count++;
}
}
System.out.println(count);
}
}