# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
819379 | AdamGS | Cake 3 (JOI19_cake3) | C++17 | 4038 ms | 7928 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const ll INF=1e18+7;
const int LIM=2e5+7;
pair<ll,ll>T[LIM];
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
ll n, m, ans=-INF;
cin >> n >> m;
rep(i, n) cin >> T[i].nd >> T[i].st;
sort(T, T+n);
rep(i, n) {
priority_queue<ll>q;
ll akt=0;
for(int j=i+1; j<n; ++j) {
if(q.size()==m-2) ans=max(ans, akt-2*T[j].st+2*T[i].st+T[i].nd+T[j].nd);
q.push(-T[j].nd);
akt+=T[j].nd;
if(q.size()>m-2) {
akt+=q.top(); q.pop();
}
}
}
cout << ans << '\n';
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |