# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
112480 | someone_aa | Cake 3 (JOI19_cake3) | C++17 | 4019 ms | 9876 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>
#define ll long long
#define pb push_back
#define mp make_pair
#define P pair<ll,ll>
using namespace std;
const int maxn = 200100;
ll n, m;
vector<P>v;
int main() {
cin>>n>>m;
ll a, b;
for(int i=0;i<n;i++) {
cin>>a>>b;
v.pb(mp(b, a));
}
sort(v.begin(), v.end());
ll result = LLONG_MIN;
for(int i=0;i<n;i++) {
if(i < m-1) continue;
multiset<ll>values;
ll sum = 0LL;
for(int j=i-1;j>=0;j--) {
if(values.size() < m - 2) {
sum += v[j].second;
values.insert(v[j].second);
}
else {
ll sum2 = sum + v[i].second + v[j].second;
ll cost = 2*(v[i].first - v[j].first);
result = max(result, sum2 - cost);
ll minvalue = *(values.begin());
if(minvalue < v[j].second) {
values.erase(values.find(minvalue));
values.insert(v[j].second);
sum += v[j].second - minvalue;
}
}
}
}
cout<<result;
return 0;
}
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... |