# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1092109 |
2024-09-23T08:09:20 Z |
juicy |
Schools (IZhO13_school) |
C++17 |
|
74 ms |
8284 KB |
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n, m, s; cin >> n >> m >> s;
vector<array<int, 2>> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i][0] >> a[i][1];
}
sort(a.begin(), a.end(), [&](const auto &u, const auto &v) {
return u[0] - u[1] > v[0] - v[1];
});
vector<int> p(n);
priority_queue<int> pq;
long long sum = 0;
for (int i = 0; i < n; ++i) {
sum += a[i][0];
pq.push(-a[i][0]);
while (pq.size() > m) {
sum += pq.top();
pq.pop();
}
p[i] = sum;
}
sum = 0;
priority_queue<int>().swap(pq);
long long res = 0;
for (int i = n; ~i; --i) {
if (i < n) {
sum += a[i][1];
pq.push(-a[i][1]);
while (pq.size() > s) {
sum += pq.top();
pq.pop();
}
}
if (pq.size() == s && i >= m) {
res = max(res, sum + (i ? p[i - 1] : 0));
}
}
cout << res;
return 0;
}
Compilation message
school.cpp: In function 'int main()':
school.cpp:28:22: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
28 | while (pq.size() > m) {
| ~~~~~~~~~~^~~
school.cpp:41:24: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
41 | while (pq.size() > s) {
| ~~~~~~~~~~^~~
school.cpp:46:19: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
46 | if (pq.size() == s && i >= m) {
| ~~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
456 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
452 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
468 KB |
Output is correct |
13 |
Correct |
8 ms |
1372 KB |
Output is correct |
14 |
Correct |
19 ms |
2216 KB |
Output is correct |
15 |
Correct |
34 ms |
3960 KB |
Output is correct |
16 |
Correct |
47 ms |
5752 KB |
Output is correct |
17 |
Incorrect |
55 ms |
6280 KB |
Output isn't correct |
18 |
Incorrect |
60 ms |
6760 KB |
Output isn't correct |
19 |
Incorrect |
65 ms |
7216 KB |
Output isn't correct |
20 |
Incorrect |
74 ms |
8284 KB |
Output isn't correct |