# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
676387 | 2022-12-30T15:15:12 Z | hgglmao | Schools (IZhO13_school) | C++17 | 176 ms | 12896 KB |
#include <bits/stdc++.h> #define fw(i, a, b, c) for (int i = a; i <= b; i += c) #define bw(i, a, b, c) for (int i = a; i >= b; i -= c) #define fauto(i, s) for (auto i : s) #define exc(x) while (x--) #define fi first #define se second #define mpr make_pair #define pb push_back #define pf push_front #define emp emplace #define eb emplace_back #define ef emplace_front #define pob pop_back #define pof pop_front #define lb lower_bound #define ub upper_bound #define str string #define vct vector #define qu queue #define dq deque #define pq priority_queue #define TASK_NAME "test" using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; // Quickread function template <class _var> void quickread(_var &cur_) { // Interger values only char _ch = 0; _var _qr = 0; while (1) { _ch = getchar(); if (_ch < '0' || _ch > '9') break; _qr = _qr * 10 + _ch - '0'; } cur_ = _qr; } const int MAX4 = 1e4 + 10; const int MAX5 = 1e5 + 10; const int MAX6 = 1e6 + 10; const int MAX7 = 1e7 + 10; const int MOD = 1e9 + 7; // Varies with task const int HASH_BASE = 31; const int PERM_HASH_BASE = 1e6 + 10; // Varies with variable limit const int csMAX = 0; class study { public: int field[2]; study() { field[0] = field[1] = 0; } study(const int &f1, const int &f2) { field[0] = f1; field[1] = f2; } bool operator<(const study &SE) { return field[0] - field[1] > SE.field[0] - SE.field[1]; } int operator[](const int &EX) { return field[EX]; } } a[3 * MAX5], req; int testcases = 1; // Variable declarations int n; int SIGN[] = {1, -1}; ll maxStudy[3 * MAX5][2], totalStudy; multiset<int> STO; // Sub-functions void GetMaxInRange(int x); // Main-functions void solve_main(); void result_export(); void debug_export(); void get_input(); void pretestcases(); void testgen() { freopen(TASK_NAME ".inp", "w", stdout); srand(time(0)); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // testgen(); return 0; if (fopen(TASK_NAME ".inp", "r")) { freopen(TASK_NAME ".inp", "r", stdin); freopen(TASK_NAME ".out", "w", stdout); } // pretestcases(); // quickread(testcases); // cin >> testcases; exc(testcases) { get_input(); solve_main(); // debug_export(); result_export(); cout << '\n'; } } void get_input() { cin >> n >> req.field[0] >> req.field[1]; fw(i, 1, n, 1) { cin >> a[i].field[0] >> a[i].field[1]; } } void solve_main() { sort(a + 1, a + n + 1); GetMaxInRange(0); GetMaxInRange(1); fw(i, 1, n, 1) { totalStudy = max(totalStudy, maxStudy[i][0] + maxStudy[i + 1][1]); } } void result_export() { cout << totalStudy; } void GetMaxInRange(int x) { int idStart = 1, idEnd = n; if (x) swap(idStart, idEnd); STO.clear(); ll maxSum = 0; for(int i = idStart; SIGN[x] * i <= SIGN[x] * idEnd; i += SIGN[x]) { maxSum += a[i][x]; STO.insert(a[i][x]); if (STO.size() > req[x]) { maxSum -= *STO.begin(); STO.erase(STO.begin()); } maxStudy[i][x] = maxSum; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2644 KB | Output is correct |
2 | Correct | 1 ms | 2644 KB | Output is correct |
3 | Correct | 1 ms | 2644 KB | Output is correct |
4 | Correct | 1 ms | 2644 KB | Output is correct |
5 | Correct | 1 ms | 2644 KB | Output is correct |
6 | Correct | 2 ms | 2644 KB | Output is correct |
7 | Correct | 3 ms | 2772 KB | Output is correct |
8 | Correct | 3 ms | 2900 KB | Output is correct |
9 | Correct | 4 ms | 2900 KB | Output is correct |
10 | Correct | 4 ms | 2900 KB | Output is correct |
11 | Correct | 3 ms | 2900 KB | Output is correct |
12 | Correct | 3 ms | 2900 KB | Output is correct |
13 | Correct | 18 ms | 4692 KB | Output is correct |
14 | Correct | 31 ms | 4840 KB | Output is correct |
15 | Correct | 50 ms | 5356 KB | Output is correct |
16 | Correct | 103 ms | 12896 KB | Output is correct |
17 | Correct | 143 ms | 11228 KB | Output is correct |
18 | Correct | 134 ms | 10776 KB | Output is correct |
19 | Correct | 146 ms | 11496 KB | Output is correct |
20 | Correct | 176 ms | 12640 KB | Output is correct |