# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
672188 | 2022-12-15T02:29:23 Z | Alihan_8 | 학교 설립 (IZhO13_school) | C++17 | 105 ms | 11396 KB |
#include <bits/stdc++.h> // include <ext/pb_ds/assoc_container.hpp> // include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; using namespace std; #define all(x) x.begin(), x.end() #define pb push_back // define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> #define mpr make_pair #define ln '\n' void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);} #define int long long signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m, s; cin >> n >> m >> s; vector <pair<int,int>> p(n); for ( auto &[l, r]: p ) cin >> l >> r; sort(all(p), [&](pair <int,int> &l, pair <int,int> &r){ return (l.first-l.second) > (r.first-r.second); }); priority_queue <int> q; vector <int> L(n), R(n); int cnt = 0; for ( int i = 0; i < n; i++ ){ auto [l, r] = p[i]; q.push(-l); cnt += l; while ( (int)q.size() > m ){ cnt -= -q.top(); q.pop(); } L[i] = cnt; } cnt = 0; while ( !q.empty() ) q.pop(); for ( int i = n-1; i >= 0; i-- ){ auto [l, r] = p[i]; q.push(-r); cnt += r; while ( (int)q.size() > s ){ cnt -= -q.top(); q.pop(); } R[i] = cnt; } int Mx = max(R[0], L.back()); for ( int i = 0; i+1 < n; i++ ){ Mx = max(Mx, L[i]+R[i+1]); } cout << Mx; cout << '\n'; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 2 ms | 468 KB | Output is correct |
8 | Correct | 2 ms | 596 KB | Output is correct |
9 | Correct | 2 ms | 468 KB | Output is correct |
10 | Correct | 2 ms | 580 KB | Output is correct |
11 | Correct | 2 ms | 468 KB | Output is correct |
12 | Correct | 2 ms | 596 KB | Output is correct |
13 | Correct | 17 ms | 2128 KB | Output is correct |
14 | Correct | 27 ms | 3724 KB | Output is correct |
15 | Correct | 47 ms | 5948 KB | Output is correct |
16 | Correct | 58 ms | 8756 KB | Output is correct |
17 | Correct | 77 ms | 8860 KB | Output is correct |
18 | Correct | 87 ms | 9584 KB | Output is correct |
19 | Correct | 98 ms | 10268 KB | Output is correct |
20 | Correct | 105 ms | 11396 KB | Output is correct |