# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
156996 | HungAnhGoldIBO2020 | Cake 3 (JOI19_cake3) | C++14 | 2 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<iostream>
#include<algorithm>
#define int long long
using namespace std;
const int N=2e5+2;
const int inf=1e18+2;
pair<int,int> val[N],dep[N];
int sum[N];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,i,j,k,ans=-inf,max1=-inf,m;
cin>>n>>m;
for(i=1;i<=n;i++){
cin>>val[i].first>>val[i].second;
}
sort(val+1,val+1+n,[&](pair<int,int> x,pair<int,int> y){
return x.second<y.second;
});
for(i=1;i<=n;i++){
sum[i]=sum[i-1]+val[i].first;
if(i>=m){
max1=max(max1,2*val[i-m+1].second+val[i-m+1].first);
ans=max(ans,max1+sum[i]-sum[i-m+1]-2*val[i].second);
// cout<<max1+sum[i]-sum[i-m+1]-2*val[i].second<<endl;
}
}
cout<<ans;
}
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... |