upload solutions
This commit is contained in:
54
C/Main.java
Normal file
54
C/Main.java
Normal file
@@ -0,0 +1,54 @@
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) throws IOException {
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
||||
int n = Integer.parseInt(br.readLine().trim());
|
||||
|
||||
long[][] pts = new long[n][2];
|
||||
for (int i = 0; i < n; i++) {
|
||||
StringTokenizer st = new StringTokenizer(br.readLine());
|
||||
pts[i][0] = Math.abs(Long.parseLong(st.nextToken()));
|
||||
pts[i][1] = Math.abs(Long.parseLong(st.nextToken()));
|
||||
}
|
||||
|
||||
Arrays.sort(pts, (p, q) -> p[0] != q[0] ? Long.compare(q[0], p[0]) : Long.compare(q[1], p[1]));
|
||||
|
||||
List<long[]> front = new ArrayList<>();
|
||||
long maxY = 0;
|
||||
int i = 0;
|
||||
while (i < n) {
|
||||
int j = i;
|
||||
long curX = pts[i][0];
|
||||
long curMaxY = 0;
|
||||
while (j < n && pts[j][0] == curX) {
|
||||
curMaxY = Math.max(curMaxY, pts[j][1]);
|
||||
j++;
|
||||
}
|
||||
if (curMaxY > maxY) {
|
||||
front.add(new long[] { curX, curMaxY });
|
||||
maxY = curMaxY;
|
||||
}
|
||||
i = j;
|
||||
}
|
||||
|
||||
int m = front.size();
|
||||
long[] dp = new long[m + 1];
|
||||
dp[m] = 0;
|
||||
|
||||
for (int ii = m - 1; ii >= 0; ii--) {
|
||||
long a = front.get(ii)[0];
|
||||
long b = 0;
|
||||
dp[ii] = Long.MAX_VALUE;
|
||||
for (int jj = ii; jj < m; jj++) {
|
||||
b = Math.max(b, front.get(jj)[1]);
|
||||
long area = 4L * a * b;
|
||||
long total = area + dp[jj + 1];
|
||||
dp[ii] = Math.min(dp[ii], total);
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(dp[0]);
|
||||
}
|
||||
}
|
||||
3
C/test1.in
Normal file
3
C/test1.in
Normal file
@@ -0,0 +1,3 @@
|
||||
2
|
||||
1 1
|
||||
-1 -1
|
||||
4
C/test2.in
Normal file
4
C/test2.in
Normal file
@@ -0,0 +1,4 @@
|
||||
3
|
||||
-7 19
|
||||
9 -30
|
||||
25 10
|
||||
7
C/test3.in
Normal file
7
C/test3.in
Normal file
@@ -0,0 +1,7 @@
|
||||
6
|
||||
1 20
|
||||
3 17
|
||||
5 15
|
||||
8 12
|
||||
9 11
|
||||
10 10
|
||||
Reference in New Issue
Block a user