#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<pair<int, int>> pa;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
pa.emplace_back(abs(x), abs(y));
}
vector<pair<int, int>> pb;
for (int i = 0; i < n; i++) {
bool ok = true;
for (int j = 0; j < n; j++) {
if (pa[j].first > pa[i].first && pa[j].second > pa[i].second) {
ok = false;
}
}
if (ok) {
pb.emplace_back(pa[i]);
}
}
sort(pb.begin(), pb.end());
int m = pb.size();
vector<long long> dp(m + 1, 1e18);
dp[0] = 0;
for (int i = 0; i < m; i++) {
int mxy = 0;
for (int j = i; j >= 0; j--) {
mxy = max(mxy, pb[j].second);
dp[i + 1] = min(dp[i + 1], dp[j] + 1LL * pb[i].first * mxy);
}
}
cout << dp[m] * 4;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
4 ms |
340 KB |
Output is correct |
9 |
Correct |
27 ms |
340 KB |
Output is correct |
10 |
Correct |
77 ms |
408 KB |
Output is correct |