제출 #620200

#제출 시각아이디문제언어결과실행 시간메모리
620200veehzCake 3 (JOI19_cake3)C++17
0 / 100
145 ms262144 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 200005; int n, m; vector<array<ll, 2>> c; // c, v pair<ll,ll> solve2(int r, int optl, int optr) { if (r<m-1) return {-1e18,-1}; // l in [optl, optr] priority_queue<ll, vector<ll>, greater<ll>> q; // v ll sum = 0; for (int i = r; i > r-m; i--) { q.push(c[i][1]); sum += c[i][1]; } pair<ll,ll> ans = {sum - 2 * (c[r][0] - c[r - m + 1][0]), r-m+1}; 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]), i}); } return ans; } ll ans = -1e18; void solve(int l, int r, int optl, int optr) { int mid = (l + r) / 2; auto [beauty, opt] = solve2(mid, optl, optr); ans = max(ans, beauty); // 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()); solve(0, n-1, 0, n-1); cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...