# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
377158 | jass921026 | Cake 3 (JOI19_cake3) | C++14 | 183 ms | 524 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;
#define jizz ios_base::sync_with_stdio(false);cin.tie(NULL);
typedef long long ll;
typedef pair<int,int> pii;
#define F first
#define S second
const ll MAXN=2E3+10, INF=1E18;
pii cake[MAXN];
priority_queue<int,vector<int>,greater<int> > pq;
int main(){ jizz
int n, m;
cin>>n>>m;
if(n>MAXN) return 0;
for(int i=0;i<n;i++){
cin>>cake[i].S>>cake[i].F;
}
sort(cake,cake+n);
ll ans=-INF;
for(int i=0;i<n;i++){
ll penalty=0, sum=0, res=-INF;
while(!pq.empty()) pq.pop();
for(int j=i;j<n;j++){
penalty=2*(cake[j].F-cake[i].F);
if(pq.size()<m){
sum+=cake[j].S;
pq.push(cake[j].S);
} else if(cake[j].S>pq.top()){
sum=sum-pq.top()+cake[j].S;
pq.pop();
pq.push(cake[j].S);
}
if(pq.size()==m) res=max(res,sum-penalty);
}
ans=max(ans,res);
}
cout<<ans<<"\n";
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... |