From 71585cbeeb1ba9ee9f9b24af49fc75ba337bf2b9 Mon Sep 17 00:00:00 2001 From: Ukj0ng <90972240+Ukj0ng@users.noreply.github.com> Date: Sat, 3 Jan 2026 15:56:56 +0900 Subject: [PATCH] =?UTF-8?q?[20260103]=20BOJ=20/=20G4=20/=20=EC=9A=B0?= =?UTF-8?q?=EC=B2=B4=EA=B5=AD=20/=20=ED=95=9C=EC=A2=85=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \354\232\260\354\262\264\352\265\255.md" | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 "Ukj0ng/202601/03 BOJ G4 \354\232\260\354\262\264\352\265\255.md" diff --git "a/Ukj0ng/202601/03 BOJ G4 \354\232\260\354\262\264\352\265\255.md" "b/Ukj0ng/202601/03 BOJ G4 \354\232\260\354\262\264\352\265\255.md" new file mode 100644 index 00000000..b50ec433 --- /dev/null +++ "b/Ukj0ng/202601/03 BOJ G4 \354\232\260\354\262\264\352\265\255.md" @@ -0,0 +1,50 @@ +``` +import java.io.*; +import java.util.*; + +public class Main { + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static int[][] villages; + private static int N; + private static long sum; + + public static void main(String[] args) throws IOException { + init(); + + long temp = 0; + int answer = 0; + for (int i = 0; i < N; i++) { + temp += villages[i][1]; + + if (temp >= (sum+1)/2) { + answer = villages[i][0]; + break; + } + } + + bw.write(answer + "\n"); + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + N = Integer.parseInt(br.readLine()); + + villages = new int[N][2]; + + for (int i = 0; i < N; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int x = Integer.parseInt(st.nextToken()); + int a = Integer.parseInt(st.nextToken()); + villages[i][0] = x; + villages[i][1] = a; + + sum += a; + } + + Arrays.sort(villages, (o1, o2) -> Integer.compare(o1[0], o2[0])); + } +} +```