# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
47566 | dqhungdl | Schools (IZhO13_school) | C++17 | 269 ms | 15344 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>
using namespace std;
typedef pair<long long,long long> ii;
long long n,A,B,res=0,f1[300005],f2[300005];
ii a[300005];
multiset<long long> s;
bool cmp(ii x1,ii x2)
{
return x1.first-x1.second>x2.first-x2.second;
}
int main()
{
ios_base::sync_with_stdio(false);
//freopen("TEST.INP","r",stdin);
//freopen("TEST.OUT","w",stdout);
cin>>n>>A>>B;
for(long long i=1;i<=n;i++)
cin>>a[i].first>>a[i].second;
sort(a+1,a+n+1,cmp);
long long sum=0;
for(long long i=1;i<=n;i++)
{
sum+=a[i].first;
s.insert(a[i].first);
if(s.size()>A)
{
sum-=*s.begin();
s.erase(s.begin());
}
f1[i]=sum;
}
s.clear();
sum=0;
for(long long i=n;i>=1;i--)
{
sum+=a[i].second;
s.insert(a[i].second);
if(s.size()>B)
{
sum-=*s.begin();
s.erase(s.begin());
}
f2[i]=sum;
}
for(long long i=A;i<=n-B;i++)
res=max(res,f1[i]+f2[i+1]);
cout<<res;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |