# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
128914 | Plurm | Cake 3 (JOI19_cake3) | C++11 | 8 ms | 376 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<long long,long long> > pieces;
for(int i = 0; i < n; i++){
scanf("%lld%lld",&v,&c);
pieces.emplace_back(v,c);
}
sort(pieces.begin(), pieces.end(), [](pair<long long, long long> x, pair<long long, long long> y){
return x.second < y.second;
});
long long ans = 123456789ll;
for(int i = 0; i < n; i++){
for(int j = i+m-1; j < n; j++){
long long highsum = 0ll;
vector<long long> use;
for(int k = i+1; k < j; k++){
use.push_back(pieces[k].first);
}
sort(use.begin(), use.end());
use.push_back(pieces[i].first);
use.push_back(pieces[j].first);
for(int k = 0; k < m; k++){
highsum += use.back();
use.pop_back();
}
highsum -= 2ll * abs(pieces[i].second - pieces[j].second);
ans = max(ans, highsum);
}
}
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... |