Submission #533224

#TimeUsernameProblemLanguageResultExecution timeMemory
533224Soumya1Cake 3 (JOI19_cake3)C++17
0 / 100
1 ms312 KiB
#include <bits/stdc++.h> #ifdef __LOCAL__ #include <debug_local.h> #endif using namespace std; void testCase() { int n, m; cin >> n >> m; vector<pair<long long, long long>> a(n); for (auto &[x, y] : a) cin >> y >> x; sort(a.begin(), a.end()); vector<long long> dp(m + 1); long long mx = 0; for (int i = 0; i < n; i++) { vector<long long> new_dp(m + 1); new_dp[1] = a[i].second + 2 * a[i].first; for (int j = 2; j < m; j++) { new_dp[j] = dp[j - 1] + a[i].second; } if (i >= m - 1) mx = max(mx, dp[m - 1] + a[i].second - 2 * a[i].first); for (int j = 1; j < m; j++) dp[j] = max(dp[j], new_dp[j]); } cout << mx << endl; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); testCase(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...