#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#include <bits/stdc++.h>
using namespace std;
#define sqr 547
#define mid (l+r)/2
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define era erase
#define C continue
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define mset multiset
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef short int si;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const ll inf=1e18;
const ll mod=1e9+7;
const ld pai=acos(-1);
ll n , m , s , ans ;
pll a[300009] ;
mset< pair < ll , pll > , greater < pair < ll , pll > > > t , ntm , nts ;
int main () {
cin >> n >> m >> s ;
for ( int i = 0 ; i < n ; i ++ ) {
cin >> a[i].fi >> a[i].se ;
}
sort ( a , a + n ) ;
reverse ( a , a + n ) ;
for ( ll i = 0 ; i < m ; i ++ ) {
ans += a[i].fi ;
t.ins ( { a[i].se - a[i].fi , { a[i].fi , a[i].se } } ) ;
}
for ( ll i = m ; i < n ; i ++ ) {
ntm .ins ( { a[i].fi , { a[i].fi , a[i].se } } ) ;
nts .ins ( { a[i].se , { a[i].fi , a[i].se } } ) ;
}
for ( ll i = 0 ; i < s ; i ++ ) {
ll val1 = nts.begin()->fi ;
ll val2 = t.begin()->se.se - t.begin()->se.fi + ntm.begin()->fi;
if ( val1 >= val2 ) {
ans += val1 ;
ll a = nts.begin()->se.fi , b = nts.begin()->se.se ;
nts .era ( nts .find ( { b , { a , b } } ) ) ;
ntm .era ( ntm .find ( { a , { a , b } } ) ) ;
}
else {
ans += val2 ;
ll A = t.begin()->se.fi , B = t.begin()->se.se ;
t .era ( t.begin() ) ;
ll a = ntm.begin()->se.fi , b = ntm.begin()->se.se ;
nts .era ( nts .find ( { b , { a , b } } ) ) ;
ntm .era ( ntm .find ( { a , { a , b } } ) ) ;
nts .ins ( { B , { A , B } } ) ;
ntm .ins ( { A , { A , B } } ) ;
t .ins ( { b - a , { a , b } } ) ;
}
}
cout << ans << endl ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
256 KB |
Output isn't correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
5 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
6 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
7 |
Incorrect |
11 ms |
1024 KB |
Output isn't correct |
8 |
Incorrect |
9 ms |
768 KB |
Output isn't correct |
9 |
Incorrect |
10 ms |
768 KB |
Output isn't correct |
10 |
Incorrect |
10 ms |
768 KB |
Output isn't correct |
11 |
Incorrect |
12 ms |
1024 KB |
Output isn't correct |
12 |
Incorrect |
12 ms |
1152 KB |
Output isn't correct |
13 |
Incorrect |
48 ms |
3832 KB |
Output isn't correct |
14 |
Incorrect |
140 ms |
11640 KB |
Output isn't correct |
15 |
Incorrect |
372 ms |
24440 KB |
Output isn't correct |
16 |
Incorrect |
471 ms |
26232 KB |
Output isn't correct |
17 |
Incorrect |
396 ms |
28408 KB |
Output isn't correct |
18 |
Incorrect |
435 ms |
31180 KB |
Output isn't correct |
19 |
Incorrect |
475 ms |
34144 KB |
Output isn't correct |
20 |
Incorrect |
558 ms |
40056 KB |
Output isn't correct |