# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
128851 | Plurm | Cake 3 (JOI19_cake3) | C++11 | 10 ms | 888 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 int long long
using namespace std;
long long sv[2048][2048];
main(){
int n,m;
scanf("%lld%lld",&n,&m);
int v,c;
vector<pair<int,int> > pieces;
for(int i = 0; i < n; i++){
scanf("%lld%lld",&v,&c);
pieces.emplace_back(v,c);
}
sort(pieces.begin(), pieces.end(), [](pair<int,int> x, pair<int,int> y){
swap(x.first, x.second);
swap(y.first, y.second);
return x < y;
});
for(int i = 0; i < n; i++){
long long highsum = 0ll;
for(int j = i+m-1; j < n; j++){
priority_queue<int, vector<int>, greater<int> > pq;
for(int k = i+1; k < j; k++){
pq.push(pieces[k].first);
}
while(pq.size() > m-2) pq.pop();
pq.push(pieces[i].first);
pq.push(pieces[j].first);
while(!pq.empty()){
highsum += 1ll * pq.top();
pq.pop();
}
sv[i][j] = highsum;
highsum = 0ll;
}
}
long long ans = 0ll;
for(int i = 0; i < n; i++){
for(int j = i+m-1; j < n; j++){
ans = max(ans, sv[i][j] + 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... |