# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1040395 | 2024-08-01T03:09:11 Z | vjudge1 | 학교 설립 (IZhO13_school) | C++14 | 79 ms | 11384 KB |
#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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 1 ms | 604 KB | Output is correct |
8 | Correct | 1 ms | 604 KB | Output is correct |
9 | Correct | 1 ms | 604 KB | Output is correct |
10 | Correct | 1 ms | 604 KB | Output is correct |
11 | Correct | 1 ms | 612 KB | Output is correct |
12 | Correct | 1 ms | 604 KB | Output is correct |
13 | Correct | 11 ms | 1884 KB | Output is correct |
14 | Correct | 19 ms | 3160 KB | Output is correct |
15 | Correct | 34 ms | 5784 KB | Output is correct |
16 | Correct | 42 ms | 7300 KB | Output is correct |
17 | Correct | 55 ms | 8660 KB | Output is correct |
18 | Correct | 62 ms | 9272 KB | Output is correct |
19 | Correct | 67 ms | 9936 KB | Output is correct |
20 | Correct | 79 ms | 11384 KB | Output is correct |