Skip to content

Commit e96186d

Browse files
authored
Merge pull request #1731 from AlgorithmWithGod/khj20006
[20251223] BOJ / G4 / 합집합 / 권혁준
2 parents 292a328 + 3d10fbe commit e96186d

File tree

1 file changed

+57
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)