Submission #673265

#TimeUsernameProblemLanguageResultExecution timeMemory
673265CutebolSchools (IZhO13_school)C++17
70 / 100
2097 ms28528 KiB
#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)

school.cpp: In function 'void fopn(std::string)':
school.cpp:5:31: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | void fopn(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
school.cpp:5:72: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | void fopn(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                                                                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...