-
카테고리
-
세부 분야
알고리즘 · 자료구조
-
해결 여부
미해결
안녕하세요. 개념이해 정상적으로 했는지 확인부탁드립니다.
22.08.29 22:28 작성 조회수 200
0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
public class AR_13 {
public static int sol(int n,int n1,int[] aa0) {
int k = n;
int max = Integer.MIN_VALUE;
int cnt = 0;
int sum = 0;
boolean is_ex = true;
while ( is_ex ) {
if( cnt == n1 - k ) is_ex = false;
for(int i = cnt; i < k + cnt;i++) {
sum += aa0[i];
}
max = Math.max(max,sum);
sum = 0;
cnt++;
}
return max;
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n1 = Integer.parseInt(st.nextToken());
int n = Integer.parseInt(st.nextToken());
int[] aa = new int[n1];
st = new StringTokenizer(br.readLine());
for(int i = 0; i < n1;i++) {
aa[i] = Integer.parseInt(st.nextToken());
}
System.out.println(sol(n,n1,aa));
}
}
슬라이딩 윈도우 개념을 이용해서 문제를 좀 다르게 푼거같은데 이렇게 풀고 정답이
나오면 정상적으로 이해한게 맞을까요?
답변을 작성해보세요.
답변 1