// XD XD
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define el cout << "\n";
using namespace std;
using ll = long long;
const int MAXN = 1e6 + 7;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll LLINF = 1e18 + 7;
template <typename T>
bool ckmin(T& a, T b) {
    return a > b ? a = b, true : false;
}
template <typename T>
bool ckmax(T& a, T b) {
    return a < b ? a = b, true : false;
}
int n;
pair<int, int> p[MAXN];
ll dp[MAXN];
void solve(int id) {
    // cout << "Case " << id << ": ";
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> p[i].first >> p[i].second;
        p[i].first = abs(p[i].first);
        p[i].second = abs(p[i].second);
    }    
    sort(p + 1, p + n + 1);
    memset(dp, 0x3f, sizeof dp);
    dp[0] = 0;
    for (int i = 1; i <= n; i++) {
        int x = p[i].first;
        int y = p[i].second;
        dp[i] = dp[i - 1] + 1LL * x * y;
        for (int j = i - 1; j >= 1; j--) {
            ckmax(x, p[j].first);
            ckmax(y, p[j].second);
            ckmin(dp[i], dp[j - 1] + 1LL * x * y);
        }
    }
    cout << 4 * dp[n] << "\n";
}
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
 
    int T = 1;
    // cin >> T;
    for (int i = 1; i <= T; i++) {
        solve(i);
    }
    return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |