#include <bits/stdc++.h>
using namespace std;
typedef pair<long long,long long> ii;
long long n,A,B,res=0,f1[100005],f2[100005];
ii a[100005];
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
school.cpp: In function 'int main()':
school.cpp:28:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(s.size()>A)
~~~~~~~~^~
school.cpp:41:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(s.size()>B)
~~~~~~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
428 KB |
Output is correct |
4 |
Correct |
2 ms |
428 KB |
Output is correct |
5 |
Correct |
2 ms |
428 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
4 ms |
672 KB |
Output is correct |
8 |
Correct |
5 ms |
928 KB |
Output is correct |
9 |
Correct |
5 ms |
928 KB |
Output is correct |
10 |
Correct |
4 ms |
1004 KB |
Output is correct |
11 |
Correct |
7 ms |
1004 KB |
Output is correct |
12 |
Correct |
4 ms |
1004 KB |
Output is correct |
13 |
Correct |
28 ms |
3196 KB |
Output is correct |
14 |
Correct |
55 ms |
4092 KB |
Output is correct |
15 |
Runtime error |
67 ms |
7328 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
16 |
Halted |
0 ms |
0 KB |
- |