Submission #620185

#TimeUsernameProblemLanguageResultExecution timeMemory
620185veehzCake 3 (JOI19_cake3)C++17
0 / 100
1 ms308 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 200005; int n, m; ll ans[MAXN]; vector<array<ll, 2>> c; // c, v ll solve2(int r, int optl, int optr) { // l in [optl, optr] priority_queue<ll, vector<ll>, greater<ll>> q; // v ll sum = 0; ll ans = 0; for (int i = r; i > r-m; i--) { q.push(c[i][1]); sum += c[i][1]; } ans = sum - 2 * (c[r][0] - c[r - m + 1][0]); for (int i = r-m; i >= optl; i--) { q.push(c[i][1]); sum += c[i][1]; sum -= q.top(); q.pop(); ans = max(ans, sum - 2*(c[r][0] - c[i][0])); } return ans; } // void solve(int l, int r, int optl, int optr) { // int mid = (l + r) / 2; // // solve for r // priority_queue<ll, vector<ll>, greater<ll>> q; // ll sum = 0; // for (int i = r; i > r - m; i--) { // q.push(c[i][1]); // sum += c[i][1]; // } // for (int i = r - m; i > 0; i--) { // } // // recurse // solve(l, mid, optl, opt); // solve(mid + 1, r, opt, optr); // } int main() { cin >> n >> m; c.resize(n); for (int i = 0; i < n; i++) cin >> c[i][1] >> c[i][0]; sort(c.begin(), c.end()); ll ans = 0; for (int i = m; i < n; i++) { ans = max(ans, solve2(i, 0, n-1)); } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...