# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
914951 | guagua0407 | Cake 3 (JOI19_cake3) | C++17 | 4011 ms | 9076 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("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
const int mxn=2e5+5;
const ll inf=1e18;
ll v[mxn],c[mxn];
ll pre[mxn];
int main() {_
int n,m;
cin>>n>>m;
vector<pair<int,int>> vec(n);
for(int i=0;i<n;i++){
cin>>vec[i].s>>vec[i].f;
}
sort(all(vec));
for(int i=1;i<=n;i++){
v[i]=vec[i-1].s;
}
for(int i=1;i<=n;i++){
c[i]=vec[i-1].f;
}
ll ans=-inf;
for(int i=1;i<=n;i++){
//cout<<v[i]<<' '<<c[i]<<'\n';
multiset<int> S;
ll sum=0;
for(int j=i;j<=n;j++){
S.insert(v[j]);
sum+=v[j];
if((int)S.size()>m){
sum-=*S.begin();
S.erase(S.begin());
}
if((int)S.size()==m){
ans=max(ans,sum-2*(c[j]-c[i]));
}
}
}
cout<<ans<<'\n';
return 0;
}
//maybe its multiset not set
//yeeorz
//laborz
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... |