# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
249440 | cheeheng | Cake 3 (JOI19_cake3) | C++14 | 4048 ms | 4032 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 pair<long long, long long> ii;
ii CV[200005];
int N, M;
priority_queue<long long, vector<int>, greater<int> > pq;
long long sum = 0;
void init(){
pq = priority_queue<long long, vector<int>, greater<int> >();
sum = 0;
}
long long insert1(long long x){
pq.push(x);
sum += x;
if(pq.size() > M){
sum -= pq.top();
pq.pop();
}
}
long long getSum(){
return sum;
}
int getSize(){
return (int)pq.size();
}
int main(){
scanf("%d%d", &N, &M);
for(int i = 0; i < N; i ++){
long long V, C;
scanf("%lld%lld", &V, &C);
CV[i] = ii(C, V);
}
sort(CV, CV+N);
long long ans = -1LL << 62;
for(int i = 0; i < N; i ++){
init();
for(int j = i; j < N; j ++){
insert1(CV[j].second);
if(getSize() == M){
ans = max(ans, getSum() - 2*(CV[j].first - CV[i].first));
}
}
}
printf("%lld", 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... |