반응형
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int[] tems = new int[n];
for(int i = 0; i < n; i++) {
tems[i] = sc.nextInt();
}
ArrayList<Integer> sums = new ArrayList<Integer>();
int i = 0;
int j = 0;
while(j < n) {
int sum = 0;
for(j = i; j < i + k; j++) {
sum += tems[j];
}
i++;
sums.add(sum);
}
Integer[] rs = sums.toArray(new Integer[0]);
Arrays.sort(rs);
System.out.println(rs[rs.length - 1]);
}
}
반응형
'프로그래밍 > 코드업 일기' 카테고리의 다른 글
코드업(CodeUp) 2016 : 천단위 구분기호 (0) | 2023.08.11 |
---|---|
코드업(CodeUp) 4721 : 투표 (0) | 2023.08.11 |
코드업(Codeup) 3015 : 성적표 출력 (실패) (0) | 2023.08.10 |
코드업(Codeup) 4691 : 주사위 네 개 (0) | 2023.08.10 |
코드업(Codeup) 4566 : 소수 (0) | 2023.08.10 |