#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+1];
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[n+1]=0;
b[n+1]=b[n];
c[0]=c[1];
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 |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
3 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 |
14 ms |
1132 KB |
Output is correct |
14 |
Correct |
34 ms |
1772 KB |
Output is correct |
15 |
Correct |
67 ms |
2924 KB |
Output is correct |
16 |
Incorrect |
73 ms |
3944 KB |
Output isn't correct |
17 |
Incorrect |
89 ms |
4720 KB |
Output isn't correct |
18 |
Incorrect |
100 ms |
4848 KB |
Output isn't correct |
19 |
Incorrect |
107 ms |
5232 KB |
Output isn't correct |
20 |
Incorrect |
124 ms |
6128 KB |
Output isn't correct |