Submission #142507

#TimeUsernameProblemLanguageResultExecution timeMemory
142507KCSCCover (COCI18_cover)C++14
120 / 120
30 ms504 KiB
#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 timeMemoryGrader output
Fetching results...