
-Code
import java.io.*;
import java.util.*;
public class BOJ27496 {
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 l = Integer.parseInt(st.nextToken());
st = new StringTokenizer(br.readLine());
int[] drinks = new int[n];
int bac = 0, cnt = 0;
for (int i = 0; i < n; i++) {
// 일정 갯수 관리를 위한 배열에 저장
drinks[i] = Integer.parseInt(st.nextToken());
// 혈중 알코올 농도 추가
bac += drinks[i];
// 갯수를 넘으면 맨 처음 더한 값 빼주기
if (i >= l) {
bac -= drinks[i - l];
}
// 원하는 알코올 농도 범위 내이면 결과 증가
if (129 <= bac && bac <= 138) {
cnt++;
}
}
System.out.println(cnt);
}
}'Beakjoon&프로그래머스 > Java' 카테고리의 다른 글
| [프로그래머스/Java] 땅따먹기 (0) | 2026.03.29 |
|---|---|
| [프로그래머스/Java] 방문 길이 (0) | 2026.03.29 |
| [프로그래머스/Java] [1차] 뉴스 클러스터링 (0) | 2026.03.28 |
| [백준/Java] 10604번 Working Hours (0) | 2026.03.28 |
| [프로그래머스/Java] 튜플 (0) | 2026.03.27 |