From 5a53e6366541bd71d23a528f9f819d5ae8b03dc9 Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Sun, 31 Aug 2025 22:41:18 +0900 Subject: [PATCH] =?UTF-8?q?[20250831]=20BOJ=20/=20G5=20/=20=EA=B0=9C?= =?UTF-8?q?=EB=98=A5=EB=B2=8C=EB=A0=88=20/=20=EC=9D=B4=EA=B0=95=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...34\353\230\245\353\262\214\353\240\210.md" | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 "lkhyun/202508/31 BOJ G5 \352\260\234\353\230\245\353\262\214\353\240\210.md" diff --git "a/lkhyun/202508/31 BOJ G5 \352\260\234\353\230\245\353\262\214\353\240\210.md" "b/lkhyun/202508/31 BOJ G5 \352\260\234\353\230\245\353\262\214\353\240\210.md" new file mode 100644 index 00000000..ae806384 --- /dev/null +++ "b/lkhyun/202508/31 BOJ G5 \352\260\234\353\230\245\353\262\214\353\240\210.md" @@ -0,0 +1,50 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + static int N,H; + + public static void main(String[] args) throws IOException { + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + H = Integer.parseInt(st.nextToken()); + + int[] top = new int[H+1]; + int[] bot = new int[H+1]; + for (int i = 0; i < N; i++) { + int cur = Integer.parseInt(br.readLine()); + if(i%2 == 0){ + bot[cur]++; + }else{ + top[cur]++; + } + } + + for (int i = H-1; i > 1; i--) { + bot[i-1] += bot[i]; + } + for (int i = H-1; i > 1; i--) { + top[i-1] += top[i]; + } + + int min = N; + int cnt = 0; + for (int i = 1; i <= H; i++) { + int cur = top[H-i+1] + bot[i]; + if(min == cur){ + cnt++; + }else if(min > cur){ + min = cur; + cnt = 1; + } + } + + bw.write(min+" "+cnt); + bw.close(); + } +} +```