#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define fi first
#define se second
#define ll long long
using namespace std;
const int N = 3e5 + 7;
const int mod = 1e9 + 7;
ll n,m,ss;
ll pr[N];
ll sf[N];
pair < ll , pair < ll , ll > > p[N];
void solve()
{
cin >> n >> m >> ss;
for( int i = 1; i <= n; i++ ){
cin >> p[i].se.fi >> p[i].se.se;
p[i].fi = p[i].se.fi - p[i].se.se;
}
sort( p + 1 , p + n + 1 );
reverse( p + 1 , p + n + 1 );
multiset < ll > s;
for( int i = 1; i <= n; i++ ){
pr[i] = pr[i - 1] + p[i].se.fi;
s.insert(p[i].se.fi);
if( (int)s.size() > m ){
pr[i] -= *s.begin();
s.erase(s.begin());
}
}
s.clear();
for( int i = n; i >= 1; i-- ){
sf[i] = sf[i + 1] + p[i].se.se;
s.insert(p[i].se.se);
if( (int)s.size() > ss ){
sf[i] -= *s.begin();
s.erase(s.begin());
}
}
ll ans = 0;
for( int i = m; i <= n - ss; i++ ){
ans = max( ans , pr[i] + sf[i + 1] );
}
cout << ans;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
//freopen( "input.txt" , "r" , stdin );
//freopen( "output.txt" , "w" , stdout );
int t = 1;//cin >> t;
while( t-- ){
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
380 KB |
Output is correct |
7 |
Correct |
4 ms |
632 KB |
Output is correct |
8 |
Correct |
5 ms |
764 KB |
Output is correct |
9 |
Correct |
5 ms |
760 KB |
Output is correct |
10 |
Correct |
8 ms |
760 KB |
Output is correct |
11 |
Correct |
5 ms |
760 KB |
Output is correct |
12 |
Correct |
5 ms |
760 KB |
Output is correct |
13 |
Correct |
28 ms |
3704 KB |
Output is correct |
14 |
Correct |
50 ms |
5368 KB |
Output is correct |
15 |
Correct |
77 ms |
8568 KB |
Output is correct |
16 |
Correct |
175 ms |
16800 KB |
Output is correct |
17 |
Correct |
209 ms |
16504 KB |
Output is correct |
18 |
Correct |
210 ms |
17020 KB |
Output is correct |
19 |
Correct |
228 ms |
18404 KB |
Output is correct |
20 |
Correct |
267 ms |
20988 KB |
Output is correct |