# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
313290 | 2020-10-15T16:34:29 Z | vitkishloh228 | 학교 설립 (IZhO13_school) | C++14 | 415 ms | 17160 KB |
#include<iostream> #include<vector> #include<queue> #include<algorithm> #define int long long using namespace std; int32_t main() { int n, m, s; cin >> n >> m >> s; vector<int> M(n), S(n); vector<pair<int, int>> ar; for (int i = 0; i < n; ++i) { cin >> M[i] >> S[i]; ar.push_back({ M[i] - S[i],i }); } sort(ar.rbegin(), ar.rend()); //reverse(ar.begin(), ar.end()); vector<int> pr(n), suf(n + 1); priority_queue< long long, vector<long long>, greater<long long> >q; int sum = 0; for (int i = 0; i < n; ++i) { int pos = ar[i].second; if (q.size() < m) { sum += M[pos]; q.push(M[pos]); pr[i] = sum; continue; } if (q.top() < M[pos]) { sum -= q.top(); q.pop(); sum += M[pos]; q.push(M[pos]); } pr[i] = sum; } sum = 0; priority_queue< long long, vector<long long>, greater<long long> >q1; for (int i = n - 1; i >= 0; --i) { int pos = ar[i].second; if (q1.size() < s) { sum += S[pos]; q1.push(S[pos]); suf[i] = sum; continue; } if (q1.top() < S[pos]) { sum -= q1.top(); q1.pop(); sum += S[pos]; q1.push(S[pos]); } suf[i] = sum; } int ans = suf[0]; for (int i = 0; i < n; ++i) { ans = max(ans, pr[i] + suf[i + 1]); } cout << ans; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 256 KB | Output is correct |
2 | Runtime error | 1 ms | 384 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
3 | Correct | 0 ms | 256 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 1 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 256 KB | Output is correct |
7 | Correct | 6 ms | 640 KB | Output is correct |
8 | Correct | 6 ms | 640 KB | Output is correct |
9 | Correct | 6 ms | 640 KB | Output is correct |
10 | Correct | 6 ms | 640 KB | Output is correct |
11 | Correct | 6 ms | 640 KB | Output is correct |
12 | Correct | 7 ms | 640 KB | Output is correct |
13 | Correct | 46 ms | 2540 KB | Output is correct |
14 | Correct | 100 ms | 4576 KB | Output is correct |
15 | Correct | 202 ms | 7904 KB | Output is correct |
16 | Correct | 234 ms | 12308 KB | Output is correct |
17 | Correct | 299 ms | 13212 KB | Output is correct |
18 | Correct | 333 ms | 14048 KB | Output is correct |
19 | Correct | 354 ms | 15072 KB | Output is correct |
20 | Correct | 415 ms | 17160 KB | Output is correct |