#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( i > 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( n - i + 1 > 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 |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
372 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
4 ms |
632 KB |
Output is correct |
8 |
Correct |
4 ms |
760 KB |
Output is correct |
9 |
Correct |
5 ms |
760 KB |
Output is correct |
10 |
Correct |
5 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 |
3320 KB |
Output is correct |
14 |
Correct |
49 ms |
4472 KB |
Output is correct |
15 |
Correct |
76 ms |
7032 KB |
Output is correct |
16 |
Correct |
175 ms |
14840 KB |
Output is correct |
17 |
Correct |
200 ms |
13872 KB |
Output is correct |
18 |
Correct |
207 ms |
14096 KB |
Output is correct |
19 |
Correct |
236 ms |
15340 KB |
Output is correct |
20 |
Correct |
262 ms |
17520 KB |
Output is correct |