Submission #530526

#TimeUsernameProblemLanguageResultExecution timeMemory
5305264fectaCake 3 (JOI19_cake3)C++17
24 / 100
186 ms67888 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define int ll #define ld long double #define pii pair<int, int> #define f first #define s second #define boost() cin.tie(0), cin.sync_with_stdio(0) const int MN = 2005; int n, m, dp[MN][MN]; pii a[MN]; void solve(int j, int l, int r, int p1, int p2) { if (l > r) return; int mid = (l + r) >> 1, opt = 0; for (int p = p1; p <= min(p2, mid - 1); p++) { if (dp[mid][j] < dp[p][j - 1] + a[mid].s - a[mid].f + a[p].f) { dp[mid][j] = dp[p][j - 1] + a[mid].s - a[mid].f + a[p].f; opt = p; } } solve(j, l, mid - 1, p1, opt), solve(j, mid + 1, r, opt, p2); } int32_t main() { boost(); cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i].s >> a[i].f, a[i].f *= 2; sort(a + 1, a + n + 1); int ans = -0x3f3f3f3f; memset(dp, -0x3f, sizeof(dp)); for (int i = 1; i <= n; i++) dp[i][1] = a[i].s; for (int j = 2; j <= m; j++) solve(j, 1, n, 1, n); for (int i = 1; i <= n; i++) ans = max(ans, dp[i][m]); printf("%lld\n", ans); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...