문제링크
https://www.acmicpc.net/problem/2559
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static int N,K;
static int temp[];
static int result = Integer.MIN_VALUE;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
K = Integer.parseInt(st.nextToken());
temp = new int[N];
st = new StringTokenizer(br.readLine());
for(int i=0;i<N;i++)
temp[i] = Integer.parseInt(st.nextToken());
for(int i=0;i<(N-K)+1;i++) {
int sum = 0;
for(int j=i;j<i+K;j++)
sum += temp[j];
if(sum>result) result = sum;
}
System.out.println(result);
}
}
'알고리즘 > 백준' 카테고리의 다른 글
[JAVA]백준_3985_롤케이크 (0) | 2021.02.25 |
---|---|
[JAVA]백준_2851_슈퍼 마리오 (0) | 2021.02.25 |
[JAVA][C++]백준_2941_크로아티아 알파벳 (0) | 2021.02.25 |
[JAVA]백준_2578_빙고 (0) | 2021.02.25 |
[JAVA]백준_10157_자리배정 (0) | 2021.02.25 |