# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
128818 | Plurm | Cake 3 (JOI19_cake3) | C++11 | 3 ms | 1016 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;
long long sv[2048][2048];
int main(){
int n,m;
scanf("%d%d",&n,&m);
int v,c;
vector<pair<int,int> > pieces;
for(int i = 0; i < n; i++){
scanf("%d%d",&v,&c);
pieces.emplace_back(v,c);
}
sort(pieces.begin(), pieces.end(), [](pair<int,int> x, pair<int,int> y){
return x.second < y.second;
});
m -= 2;
for(int i = 0; i+m-1 < n; i++){
long long highsum = 0ll;
multiset<int> ms;
for(int j = i; j < i+m; j++){
highsum += 1ll * pieces[j].first;
ms.insert(pieces[j].first);
}
sv[i][i+m-1] = highsum;
for(int j = i+m; j < n; j++){
if(pieces[j].first > *ms.begin()){
highsum -= 1ll * *ms.begin();
ms.erase(ms.begin());
ms.insert(pieces[j].first);
highsum += 1ll * pieces[j].first;
}
sv[i][j] = highsum;
}
}
m += 2;
long long ans = 0ll;
for(int i = 0; i+m < n; i++){
for(int j = i+m; j < n; j++){
ans = max(ans, sv[i+1][j-1] + 1ll * pieces[i].first + 1ll * pieces[j].first + 2ll * pieces[i].second - 2ll * pieces[j].second);
}
}
printf("%lld\n",ans);
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... |