File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed
Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments