Submission #225738

# Submission time Handle Problem Language Result Execution time Memory
225738 2020-04-21T12:58:11 Z infinite_iq Schools (IZhO13_school) C++14
100 / 100
556 ms 36472 KB
#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 ;
}

Compilation message

school.cpp: In function 'int main()':
school.cpp:59:28: warning: unused variable 'A' [-Wunused-variable]
                         ll A = t.begin()->se.fi , B = t.begin()->se.se ;
                            ^
school.cpp:59:51: warning: unused variable 'B' [-Wunused-variable]
                         ll A = t.begin()->se.fi , B = t.begin()->se.se ;
                                                   ^
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 10 ms 896 KB Output is correct
8 Correct 9 ms 640 KB Output is correct
9 Correct 10 ms 768 KB Output is correct
10 Correct 10 ms 768 KB Output is correct
11 Correct 11 ms 896 KB Output is correct
12 Correct 13 ms 1024 KB Output is correct
13 Correct 47 ms 3448 KB Output is correct
14 Correct 176 ms 10744 KB Output is correct
15 Correct 306 ms 22648 KB Output is correct
16 Correct 481 ms 24312 KB Output is correct
17 Correct 427 ms 25948 KB Output is correct
18 Correct 440 ms 28536 KB Output is correct
19 Correct 476 ms 31096 KB Output is correct
20 Correct 556 ms 36472 KB Output is correct