Skip to content

Commit 322914f

Browse files
authored
Merge pull request #156 from AlgorithmWithGod/khj20006
[20250220] BOJ / G2 / 기지국 / 권혁준
2 parents 6b473c8 + 7701249 commit 322914f

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
```cpp
2+
3+
#include <iostream>
4+
#include <vector>
5+
#include <algorithm>
6+
using namespace std;
7+
using ll = long long;
8+
9+
int main()
10+
{
11+
cin.tie(0)->sync_with_stdio(0);
12+
13+
int N;
14+
ll inf = 1e18;
15+
cin >> N;
16+
vector<pair<ll, ll>> A(N);
17+
for (auto &[x, y] : A) cin >> x >> y;
18+
sort(A.begin(), A.end());
19+
20+
vector<ll> dp(10000, inf);
21+
dp[0] = abs(A[0].second) * 2;
22+
for (int i = 1; i < N; i++) {
23+
int p = i;
24+
ll maxabs = -1;
25+
while (i < N && A[p].first == A[i].first) maxabs = max(maxabs, abs(A[i++].second));
26+
i--;
27+
for (int j = p - 1; j >= 0; j--) {
28+
maxabs = max(maxabs, abs(A[j+1].second));
29+
dp[i] = min(dp[i], dp[j] + max(maxabs * 2, A[i].first - A[j + 1].first));
30+
}
31+
maxabs = max(maxabs, abs(A[0].second));
32+
dp[i] = min(dp[i], max(maxabs * 2, A[i].first - A[0].first));
33+
}
34+
cout << dp[N - 1];
35+
36+
}
37+
38+
```

0 commit comments

Comments
 (0)