Submission #1040395

#TimeUsernameProblemLanguageResultExecution timeMemory
1040395vjudge1Schools (IZhO13_school)C++14
100 / 100
79 ms11384 KiB
#include<bits/stdc++.h> using namespace std ; #define maxn 300009 #define ll long long #define pb push_back #define fi first #define se second #define left id<<1 #define right id<<1|1 #define re exit(0); #define _lower(x) lower_bound(v.begin(),v.end(),x)-v.begin()+1 const int mod = 1e9+7 ; const int INF = 1e9 ; typedef vector<int> vi ; typedef pair<int,int> pii ; typedef vector<pii> vii ; template < typename T > void chkmin ( T &a , T b ) { if ( a > b ) a = b ; } template < typename T > void chkmax ( T &a , T b ) { if ( a < b ) a = b ; } void add ( int &a , int b ) { a += b ; if ( a >= mod ) a -= mod ; if ( a < 0 ) a += mod ; } void rf () { freopen ("bai1.inp","r",stdin) ; } int _pow ( int a , int n ) { if ( n == 0 ) return 1 ; int res = _pow (a,n/2) ; if ( n % 2 ) return 1ll*res*res%mod*a%mod ; else return 1ll*res*res%mod ; } int n , m1 , m2 ; pii a [maxn] ; bool cmp ( pii u , pii v ) { return u.fi + v.se > u.se + v.fi ; } ll L [maxn],R[maxn] ; int main () { ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); // rf () ; cin >> n >> m1 >> m2 ; for ( int i = 1 ; i <= n ; i ++ ) { cin >> a [i].fi >> a[i].se ; } sort(a+1,a+n+1,cmp) ; // for ( int i = 1 ; i <= n ; i ++ ) cout << a[i].fi << " " << a[i].se << "\n" ; re priority_queue<int,vi,greater<int>> S ; ll sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { sum += a[i].fi ; S.push(a[i].fi) ; if ( S.size() > m1 ) sum -= S.top() , S.pop() ; if ( S.size() == m1 ) L [i] = sum ; else L [i] = -1e18 ; } while (S.size()) S.pop() ; sum = 0 ; for ( int i = n ; i >= 1 ; i -- ) { sum += a[i].se ; S.push(a[i].se) ; if ( S.size() > m2 ) sum -= S.top() , S.pop() ; if ( S.size() == m2 ) R [i] = sum ; else R[i] = -1e18 ; } ll res = -1e18 ; for ( int i = m1+1 ; i <= n-m2+1 ; i ++ ) chkmax (res,L[i-1]+R[i]) ; cout << res ; }

Compilation message (stderr)

school.cpp: In function 'int main()':
school.cpp:67:17: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   67 |   if ( S.size() > m1 ) sum -= S.top() , S.pop() ;
      |        ~~~~~~~~~^~~~
school.cpp:68:17: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   68 |   if ( S.size() == m1 ) L [i] = sum ;
      |        ~~~~~~~~~^~~~~
school.cpp:77:17: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   77 |   if ( S.size() > m2 ) sum -= S.top() , S.pop() ;
      |        ~~~~~~~~~^~~~
school.cpp:78:17: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   78 |   if ( S.size() == m2 ) R [i] = sum ;
      |        ~~~~~~~~~^~~~~
school.cpp: In function 'void rf()':
school.cpp:31:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |  freopen ("bai1.inp","r",stdin) ;
      |  ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...