Submission #138913

#TimeUsernameProblemLanguageResultExecution timeMemory
138913Mahmoud_AdelCake 3 (JOI19_cake3)C++14
0 / 100
3 ms376 KiB
#include <bits/stdc++.h> #define f first #define s second using namespace std; typedef long long ll; const int N = 1e5+5; ll n, k, ans; pair<ll, ll> p[N]; bool cmp(pair<ll, ll> a, pair<ll, ll> b) { return a.s < b.s; } ll sum(int l, int r) { vector<ll> vec; ll ret = 0; for(int i=l; i<=r; i++) { vec.push_back(p[i].f); } sort(vec.rbegin(), vec.rend()); for(int i=0; i<min(k, (ll)vec.size()); i++) ret += vec[i]; return ret; } void solve(int l, int r, int s, int e) { if(l > r) return ; ll id = -1, m = -1; ll mid = (l+r)>>1; for(int i=max(mid+k-1, (ll)s); i<e; i++) { if(sum(mid, i) - (p[i].s-p[mid].s)*2 > m) m = sum(mid, i) - (p[i].s-p[mid].s)*2, id = i; } solve(l, mid-1, s, id+1); solve(mid+1, r, id, e); ans = max(ans, m); } int main() { cin >> n >> k; for(int i=0; i<n; i++) cin >> p[i].f >> p[i].s; sort(p, p+n, cmp); solve(0, n-k+1, k-1, n); cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...