# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
171744 | 2019-12-30T09:03:44 Z | davitmarg | 학교 설립 (IZhO13_school) | C++17 | 277 ms | 18556 KB |
/*DavitMarg*/ #include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <string> #include <cstring> #include <map> #include <unordered_map> #include <set> #include <queue> #include <iomanip> #include <bitset> #include <stack> #include <cassert> #include <iterator> #include <fstream> #define mod 1000000007ll #define LL long long #define LD long double #define MP make_pair #define PB push_back #define all(v) v.begin(), v.end() using namespace std; const int N = 300005; int n, m, k; LL ans, pr[N], sf[N]; pair<LL, LL> a[N]; multiset<LL> s; int main() { cin >> n >> m >> k; for (int i = 1; i <= n; i++) scanf("%lld%lld", &a[i].first, &a[i].second); sort(a + 1, a + 1 + n, [](pair<LL, LL> a, pair<LL, LL> b) { return a.first - a.second > b.first - b.second; }); for (int i = 1; i <= n; i++) { pr[i] = pr[i - 1] + a[i].first; s.insert(a[i].first); if (s.size() > m) { pr[i] -= (*s.begin()); s.erase(s.begin()); } } s.clear(); for (int i = n; i >= 1; i--) { sf[i] = sf[i + 1] + a[i].second; s.insert(a[i].second); if (s.size() > k) { sf[i] -= (*s.begin()); s.erase(s.begin()); } } for (int i = 1; i <= n; i++) ans = max(pr[i] + sf[i + 1], ans); cout << ans << endl; return 0; } /* 3 1 1 100 0 100 50 0 20 4 1 1 100 0 550 500 500 550 0 100 3 1 1 100 0 500 550 0 100 */
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 380 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 4 ms | 504 KB | Output is correct |
8 | Correct | 5 ms | 760 KB | Output is correct |
9 | Correct | 5 ms | 632 KB | Output is correct |
10 | Correct | 5 ms | 692 KB | Output is correct |
11 | Correct | 5 ms | 764 KB | Output is correct |
12 | Correct | 5 ms | 732 KB | Output is correct |
13 | Correct | 30 ms | 3320 KB | Output is correct |
14 | Correct | 50 ms | 4600 KB | Output is correct |
15 | Correct | 77 ms | 7288 KB | Output is correct |
16 | Correct | 185 ms | 15328 KB | Output is correct |
17 | Correct | 214 ms | 14704 KB | Output is correct |
18 | Correct | 220 ms | 15144 KB | Output is correct |
19 | Correct | 241 ms | 16068 KB | Output is correct |
20 | Correct | 277 ms | 18556 KB | Output is correct |