Submission #142507

# Submission time Handle Problem Language Result Execution time Memory
142507 2019-08-09T10:43:50 Z KCSC Cover (COCI18_cover) C++14
120 / 120
30 ms 504 KB
#include <bits/stdc++.h>
using namespace std;

const int DIM = 5005;

long long dp[DIM];
pair<int, int> pts[DIM];

int main(void) {
   // freopen("cover.in", "r", stdin);
   // freopen("cover.out", "w", stdout);
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> pts[i].first >> pts[i].second;
        if (pts[i].first < 0)
            pts[i].first *= -1;
        if (pts[i].second < 0)
            pts[i].second *= -1;
    }
    sort(pts + 1, pts + n + 1);
    for (int i = 1; i <= n; ++i) {
        dp[i] = 1LL << 60;
        for (int j = i, v = pts[i].second; j >= 1; --j) {
            v = max(v, pts[j].second);
            dp[i] = min(dp[i], dp[j - 1] + 4LL * v * pts[i].first);
        }
    }
    cout << dp[n];
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 4 ms 504 KB Output is correct
9 Correct 14 ms 376 KB Output is correct
10 Correct 30 ms 504 KB Output is correct