문제 - 3020
그림과 같을 때 N의 길이를 지날 때 그전에 배열의 값과 현재의 배열의 값을 더해주면 된다.
종유석은 반대로 자라기 때문에 전체의 크기에서 빼주어서 값을 구해준다.
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int h = sc.nextInt();
int up[] = new int[h+1];
int down[] = new int[h+1];
//종유석 석순 저장 h 보다 작은 수
for(int i=0;i<n;i++)
{
if(i % 2 ==0) down[sc.nextInt()]++;
else up[sc.nextInt()]++;
}
//누적합
for(int i=h-1;i>-1;i--)
{
up[i] += up[i+1];
down[i] += down[i+1];
}
int ans = n;
int cnt = 0;
for(int i=1;i<h+1;i++)
{
int total = up[h-i+1] + down[i
];
if( total < ans)
{
ans = total;
cnt = 1;
}else if(total == ans)
{
cnt++;
}
}
System.out.println(ans +" "+cnt);
}
}