# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
502026 | Aktan | Schools (IZhO13_school) | C++17 | 283 ms | 25496 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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define ft first
#define sc second
using namespace std;
const int mod=1e9+7,INF=1e17,N=3e5+5;
int pr[N],sf[N];
main(){
int n,m,k;
cin >> n >> m >> k;
vector<int> a(n),b(n);
vector<pair<pair<int,int>,int>> v;
for(int i=0;i<n;i++){
cin >> a[i] >> b[i];
v.push_back({{a[i]-b[i],a[i]},b[i]});
}
sort(v.rbegin(),v.rend());
int sum=0;
multiset<int> s;
for(int i=0;i<n;i++){
sum+=v[i].ft.sc;
s.insert(v[i].ft.sc);
if(s.size()>m){
sum-=*s.begin();
s.erase(s.begin());
}
pr[i]=sum;
}
s.clear();
sum=0;
for(int i=n-1;i>=0;i--){
sum+=v[i].sc;
s.insert(v[i].sc);
if(s.size()>k){
sum-=*s.begin();
s.erase(s.begin());
}
sf[i]=sum;
}
int ans=0;
for(int i=0;i<n;i++){
ans=max(ans,pr[i]+sf[i+1]);
}
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |