# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
348813 | nicolaalexandra | Schools (IZhO13_school) | C++14 | 382 ms | 13548 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>
#define DIM 300010
using namespace std;
pair <int,int> v[DIM];
int a[DIM],b[DIM];
long long pref[DIM],suf[DIM];
multiset <int> s;
int n,nra,nrb,i;
int main (){
//ifstream cin ("date.in");
//ofstream cout ("date.out");
cin>>n>>nra>>nrb;
for (i=1;i<=n;i++){
cin>>a[i]>>b[i];
v[i] = make_pair(b[i]-a[i],i);
}
sort (v+1,v+n+1);
long long sum = 0;
for (i=1;i<=nra;i++){
sum += a[v[i].second];
s.insert(a[v[i].second]);
}
pref[nra] = sum;
for (i=nra+1;i<=n;i++){
sum += a[v[i].second];
s.insert(a[v[i].second]);
/// scad minimul din set
sum -= *s.begin();
s.erase(s.begin());
pref[i] = sum;
}
sum = 0;
s.clear();
for (i=n-nrb+1;i<=n;i++){
sum += b[v[i].second];
s.insert(b[v[i].second]);
}
suf[n-nrb+1] = sum;
for (i=n-nrb;i;i--){
sum += b[v[i].second];
s.insert(b[v[i].second]);
sum -= *s.begin();
s.erase(s.begin());
suf[i] = sum;
}
long long sol = 0;
for (i=0;i<=n;i++)
sol = max (sol,pref[i] + suf[i+1]);
cout<<sol;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |