File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments