#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN=3e5+6;
int n,m,s;
struct city
{
ll a,b;
bool operator<(city const& other)const
{
if(a-b!=other.a-other.b)return a-b>other.a-other.b;
return make_pair(a,b)>make_pair(a,b);
}
};
city c[MAXN];
ll best1[MAXN],best2[MAXN];
priority_queue<ll>pq;
int main()
{
cin>>n>>m>>s;
for(int i=1;i<=n;i++)
{
cin>>c[i].a>>c[i].b;
}
sort(c+1,c+n+1);
best1[0]=0;
ll sum=0;
/*for(int i=1;i<=n;i++)
{
cout<<c[i].a<<" "<<c[i].b<<endl;
}*/
for(int i=1;i<=n;i++)
{
sum+=c[i].a;
pq.push(-c[i].a);
if(i>m)
{
sum+=pq.top();
pq.pop();
}
best1[i]=sum;
}
sum=0;
best2[n+1]=0;
for(int i=n;i>=1;i--)
{
sum+=c[i].b;
pq.push(-c[i].b);
if(n-i+1>s)
{
sum+=pq.top();
pq.pop();
}
best2[i]=sum;
}
ll ans=0;
for(int i=m;i+s<=n;i++)
{
ans=max(ans,best1[i]+best2[i+1]);
}
/*for(int i=1;i<=n;i++)cout<<best1[i]<<" ";
cout<<endl;
for(int i=1;i<=n;i++)cout<<best2[i]<<" ";
cout<<endl;*/
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
296 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
4 ms |
440 KB |
Output is correct |
8 |
Correct |
4 ms |
612 KB |
Output is correct |
9 |
Incorrect |
5 ms |
588 KB |
Output isn't correct |
10 |
Incorrect |
6 ms |
460 KB |
Output isn't correct |
11 |
Correct |
4 ms |
588 KB |
Output is correct |
12 |
Correct |
4 ms |
588 KB |
Output is correct |
13 |
Incorrect |
35 ms |
2196 KB |
Output isn't correct |
14 |
Correct |
62 ms |
3952 KB |
Output is correct |
15 |
Correct |
139 ms |
7104 KB |
Output is correct |
16 |
Correct |
179 ms |
9528 KB |
Output is correct |
17 |
Correct |
174 ms |
11256 KB |
Output is correct |
18 |
Correct |
190 ms |
12080 KB |
Output is correct |
19 |
Correct |
212 ms |
13008 KB |
Output is correct |
20 |
Correct |
257 ms |
14896 KB |
Output is correct |