| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 388648 | kshitij_sodani | Cake 3 (JOI19_cake3) | C++14 | 1 ms | 316 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.
//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
#define endl '\n'
llo n,m;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>m;
vector<pair<llo,llo>> ss;
for(llo i=0;i<n;i++){
llo aa,bb;
cin>>aa>>bb;
ss.pb({bb,aa});
}
sort(ss.begin(),ss.end());
llo la=-1;
llo ans=0;
/* for(auto j:ss){
cout<<j.a<<"."<<j.b<<endl;
}*/
for(llo i=0;i<n;i++){
llo su=ss[i].b+2*ss[i].a;
priority_queue<llo> tt;
pair<llo,llo> ma={-1,-1};
for(llo j=i+1;j<n;j++){
while(tt.size()>m-2){
su+=tt.top();
tt.pop();
}
if(j>=la){
if(tt.size()>=m-2){
pair<llo,llo> cur={su+ss[j].b-ss[j].a*2,j};
if(cur.a>ma.a){
ma=cur;
}
/* if(cur.a==20){
cout<<i<<":"<<j<<endl;
}*/
}
}
su+=ss[j].b;
tt.push(-ss[j].b);
}
ans=max(ans,ma.a);
la=ma.b;
}
cout<<ans<<endl;
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... | ||||
