Skip to content

Commit 1a26607

Browse files
authored
Merge pull request #213 from AlgorithmWithGod/khj20006
[20250307] BOJ / G3 / 화학실험 / 권혁준
2 parents e43eeeb + 0ec52fa commit 1a26607

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
```

0 commit comments

Comments
 (0)