수열 A가 주어질 것이다.
X일 동안 가장 많이 들어온 방문자 수와, 그 때의 기간을 반환하는 문제이다.
투 포인터? 라고 하기에도 애매한 문제이다.
1 ~ X번째 방문자 수를 먼저 계산하여 A를 도출한다.
이후 A에서 1을 빼주고(즉 가장 앞에 값), X+1번째 값을 더해주면(즉 이전 범위 다음 값)을 2 ~ X+1번째의 범위값에 대한 방문자 수가 되는 것이다.
따라서, 이렇게 포인터를 동시에 하나씩 오른쪽으로 움직여가며 최댓값을 계산하면 된다.
import java.io.*;
import java.util.*;
public class Main {
static StringBuilder sb = new StringBuilder();
static FastReader sc = new FastReader();
public static void main(String[] args) {
int N = sc.nextInt();
int X = sc.nextInt();
int[] arr = new int[N];
for(int i =0;i<N;i++) arr[i] = sc.nextInt();
int max = 0;
int ans = 0;
for(int i = 0;i<X;i++) {
ans+=arr[i];
}
max = ans;
int count = 1;
for(int i =X;i<N;i++) {
ans = ans - arr[i-X] + arr[i];
if(max==ans) count++;
else if(max < ans) {
max = ans;
count = 1;
}
}
if(max==0) {
System.out.println("SAD");
}
else {
System.out.println(max);
System.out.println(count);
}
}
static class FastReader // 빠른 입력을 위한 클래스
}