File tree Expand file tree Collapse file tree 1 file changed +74
-0
lines changed
Expand file tree Collapse file tree 1 file changed +74
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+
3+ import java.util.* ;
4+ import java.io.* ;
5+
6+
7+ class Main {
8+
9+ // IO field
10+ static BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
11+ static BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (System . out));
12+ static StringTokenizer st;
13+
14+ static void nextLine () throws Exception {st = new StringTokenizer (br .readLine ());}
15+ static int nextInt() {return Integer . parseInt(st. nextToken());}
16+ static long nextLong() {return Long . parseLong(st. nextToken());}
17+ static void bwEnd() throws Exception {bw. flush();bw. close();}
18+
19+ // Additional field
20+
21+ static int N , M ;
22+ static int [] A , B ;
23+
24+ static PriorityQueue<int[]> Q = new PriorityQueue<> ((a,b) - > {
25+ if (a[0 ] == b[0 ]) return a[1 ]- b[1 ];
26+ return a[0 ]- b[0 ];
27+ });
28+ static int [] cnt;
29+
30+ public static void main(String [] args) throws Exception {
31+
32+ ready();
33+ solve();
34+
35+ bwEnd();
36+
37+ }
38+
39+ static void ready() throws Exception {
40+
41+ N = Integer . parseInt(br. readLine());
42+ A = new int [N ];
43+ B = new int [N ];
44+ cnt = new int [1001001 ];
45+ for (int i= 0 ;i< N ;i++ ) {
46+ nextLine();
47+ A [i] = nextInt();
48+ B [i] = nextInt();
49+ Q . offer(new int [] {A [i]+ B [i],A [i]});
50+ cnt[A [i]+ B [i]]++ ;
51+ }
52+
53+ M = Integer . parseInt(br. readLine()) - N ;
54+
55+ }
56+
57+ static void solve() throws Exception {
58+
59+ for (int i= 0 ;i< M ;i++ ) {
60+ int [] now = Q . poll();
61+ cnt[now[0 ]]-- ;
62+ cnt[now[0 ]+ now[1 ]]++ ;
63+ Q . offer(new int [] {now[0 ]+ now[1 ], now[1 ]});
64+ }
65+ int x = Q . poll()[0 ];
66+ if (cnt[x] == N ) bw. write(x + " \n " );
67+ else bw. write(" 0" );
68+
69+
70+ }
71+
72+ }
73+
74+ ```
You can’t perform that action at this time.
0 commit comments