Submission #1142383

#TimeUsernameProblemLanguageResultExecution timeMemory
1142383VMaksimoski008Cake 3 (JOI19_cake3)C++20
24 / 100
184 ms327680 KiB
#include <bits/stdc++.h>
#define ar array
//#define int long long

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int mod = 1e9 + 7;
const ll inf = 1e18;
const int maxn = 1e5 + 5;

signed main() {
    ios_base::sync_with_stdio(false);
    cout.tie(0); cin.tie(0);

    int n, m; cin >> n >> m;
    vector<ar<int, 2> > a(n+1);
    for(int i=1; i<=n; i++) cin >> a[i][1] >> a[i][0];
    sort(a.begin()+1, a.end());

    ll dp[n+1][m+1];
    for(int i=0; i<=n; i++)
        for(int j=0; j<=m; j++) dp[i][j] = -1e18;
    dp[0][0] = 0;

    for(int i=1; i<=n; i++) {
        for(int j=0; j<=m; j++) {
            dp[i][j] = dp[i-1][j];
            ll cost = a[i][1];
            if(j == 1) cost += 2ll * a[i][0];
            if(j == m) cost -= 2ll * a[i][0];
            if(j) dp[i][j] = max(dp[i][j], dp[i-1][j-1] + cost);
        }
    }

    cout << dp[n][m] << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...