#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
using namespace std;
bool cmp(pii& a, pii& b)
{
return a.f-a.s<b.f-b.s;
}
ll max(ll a, ll b)
{
if (a>b)
return a;
return b;
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
int n,M,S;
ll sum=0,ans=0;
cin>>n>>M>>S;
pii a[n+2];
for (int i=1;i<=n;++i)
cin>>a[i].f>>a[i].s;
sort(a+1,a+n+1,cmp);
int b[n+2],c[n+2];
priority_queue<int,vector<int>,greater<int>> p,q;
for (int i=1;i<=n;++i)
{
sum+=a[i].s;
p.push(a[i].s);
if (i>S)
{
sum-=p.top();
p.pop();
}
b[i]=sum;
}
sum=0;
for (int i=n;i;--i)
{
sum+=a[i].f;
q.push(a[i].f);
if (n-i>=M)
{
sum-=q.top();
q.pop();
}
c[i]=sum;
}
b[0]=c[0]=b[n+1]=c[n+1]=0;
for (int i=0;i<=n;++i)
ans=max(ans,b[i]+c[i+1]);
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
492 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
2 ms |
492 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
11 |
Correct |
2 ms |
492 KB |
Output is correct |
12 |
Correct |
2 ms |
492 KB |
Output is correct |
13 |
Correct |
15 ms |
1516 KB |
Output is correct |
14 |
Correct |
42 ms |
2668 KB |
Output is correct |
15 |
Correct |
62 ms |
4588 KB |
Output is correct |
16 |
Incorrect |
75 ms |
5992 KB |
Output isn't correct |
17 |
Incorrect |
90 ms |
7152 KB |
Output isn't correct |
18 |
Incorrect |
101 ms |
7684 KB |
Output isn't correct |
19 |
Incorrect |
113 ms |
8304 KB |
Output isn't correct |
20 |
Incorrect |
125 ms |
9456 KB |
Output isn't correct |