Submission #530524

#TimeUsernameProblemLanguageResultExecution timeMemory
5305244fectaCake 3 (JOI19_cake3)C++17
0 / 100
1 ms716 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];

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 = 0;
    for (int i = 1; i <= n; i++) {
        dp[i][1] = a[i].s;
        for (int j = 2; j <= m; j++) {
            for (int p = 1; p < i; p++) dp[i][j] = max(dp[i][j], dp[p][j - 1] + a[i].s - a[i].f + a[p].f);
        }
        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...