Skip to content

Commit fd8a80c

Browse files
authored
Merge pull request #1765 from AlgorithmWithGod/Ukj0ng
[20260103] BOJ / G4 / 우체국 / 한종욱
2 parents 5ede766 + 71585cb commit fd8a80c

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
```
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+
private static int[][] villages;
9+
private static int N;
10+
private static long sum;
11+
12+
public static void main(String[] args) throws IOException {
13+
init();
14+
15+
long temp = 0;
16+
int answer = 0;
17+
for (int i = 0; i < N; i++) {
18+
temp += villages[i][1];
19+
20+
if (temp >= (sum+1)/2) {
21+
answer = villages[i][0];
22+
break;
23+
}
24+
}
25+
26+
bw.write(answer + "\n");
27+
bw.flush();
28+
bw.close();
29+
br.close();
30+
}
31+
32+
private static void init() throws IOException {
33+
N = Integer.parseInt(br.readLine());
34+
35+
villages = new int[N][2];
36+
37+
for (int i = 0; i < N; i++) {
38+
StringTokenizer st = new StringTokenizer(br.readLine());
39+
int x = Integer.parseInt(st.nextToken());
40+
int a = Integer.parseInt(st.nextToken());
41+
villages[i][0] = x;
42+
villages[i][1] = a;
43+
44+
sum += a;
45+
}
46+
47+
Arrays.sort(villages, (o1, o2) -> Integer.compare(o1[0], o2[0]));
48+
}
49+
}
50+
```

0 commit comments

Comments
 (0)