# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
673265 | Cutebol | Schools (IZhO13_school) | C++17 | 2097 ms | 28528 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
void fopn(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
#define Scaramouche ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0);
#define int long long
#define itn int
#define endl "\n"
#define ff first
#define ss second
const int N = 3e5 + 5 ;
const int mod = 1e9 + 7 ;
const int inf = 1e12 ;
int n , k , m , sum ;
int pref[N] , suf[N] ;
int a[N] , b[N] ;
multiset <int> st ;
void solve(){
cin >> n >> m >> k ;
for ( int i = 0 ; i < n ; i ++ ) cin >> a[i] >> b[i] ;
vector < pair <int , pair <int , int> > > vec ;
for ( int i = 0 ; i < n ; i ++ )
vec.push_back({a[i]-b[i],{a[i],b[i]}}) ;
sort ( vec.rbegin() , vec.rend() ) ;
for ( int i = 0 ; i < m ; i ++ ){
st.insert(vec[i].ss.ff) ;
sum += vec[i].ss.ff ;
}
pref[m-1] = sum ;
for ( int i = m ; i < n ; i ++ ){
if ( vec[i].ss.ff > *st.begin() ){
sum -= *st.begin() ;
st.erase(st.begin()) ;
st.insert(vec[i].ss.ff) ;
sum += vec[i].ss.ff ;
}
pref[i] = sum ;
}
st.clear() ;
sum = 0 ;
for ( int i = n - 1 ; i >= n - k ; i -- ){
st.insert(vec[i].ss.ss) ;
sum += vec[i].ss.ss ;
}
suf[n-k] = sum ;
for ( int i = n - k - 1 ; i >= 0 ; i -- ){
if ( vec[i].ss.ss > *st.begin() ){
sum -= *st.begin() ;
st.erase(st.begin()) ;
st.insert(vec[i].ss.ss) ;
sum += vec[i].ss.ss ;
}
suf[i] = sum ;
}
int ans = 0 ;
for ( int i = m-1 ; i < n ; i ++ ) ans = max ( ans , pref[i]+suf[i+1] ) ;
cout << ans << endl ;
for ( int i = 0 ; i < n ; i ++ ) cerr << vec[i].ff << ' ' << vec[i].ss.ff << ' ' << vec[i].ss.ss << endl ;
for ( int i = 0 ; i < n ; i ++ ) cerr << pref[i] << ' ' << suf[i] << endl ;
}
signed main(){
// fopn("blocks") ;
// Scaramouche ;
int t = 1 ;
// cin >> t ;
while ( t -- ) solve() ;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |