# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
47526 |
2018-05-05T02:26:40 Z |
aome |
Schools (IZhO13_school) |
C++17 |
|
191 ms |
9476 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
int n, m, q, a[N], b[N], p[N];
long long f[N], g[N], s, res;
bool cmp(int x, int y) {
return a[x] - b[x] < a[y] - b[y];
}
int main() {
ios::sync_with_stdio(false);
cin >> n >> m >> q;
for (int i = 0; i < n; ++i) cin >> a[i] >> b[i];
for (int i = 0; i < n; ++i) p[i] = i;
sort(p, p + n, cmp);
priority_queue<int> pq;
s = 0;
for (int i = 0; i < n; ++i) {
pq.push(-b[p[i]]); s += b[p[i]];
if (pq.size() > q) {
s += pq.top(); pq.pop();
}
f[i] = s;
}
while (pq.size()) pq.pop();
s = 0;
for (int i = n - 1; i >= 0; --i) {
pq.push(-a[p[i]]); s += a[p[i]];
if (pq.size() > m) {
s += pq.top(); pq.pop();
}
g[i] = s;
}
for (int i = q - 1; i < n - m; ++i) res = max(res, f[i] + g[i + 1]);
cout << res;
}
Compilation message
school.cpp: In function 'int main()':
school.cpp:23:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (pq.size() > q) {
~~~~~~~~~~^~~
school.cpp:32:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (pq.size() > m) {
~~~~~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
484 KB |
Output is correct |
4 |
Correct |
2 ms |
484 KB |
Output is correct |
5 |
Correct |
2 ms |
520 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
4 ms |
868 KB |
Output is correct |
8 |
Correct |
3 ms |
868 KB |
Output is correct |
9 |
Correct |
4 ms |
868 KB |
Output is correct |
10 |
Correct |
4 ms |
868 KB |
Output is correct |
11 |
Correct |
4 ms |
868 KB |
Output is correct |
12 |
Correct |
4 ms |
868 KB |
Output is correct |
13 |
Correct |
19 ms |
1788 KB |
Output is correct |
14 |
Correct |
46 ms |
2940 KB |
Output is correct |
15 |
Correct |
82 ms |
4988 KB |
Output is correct |
16 |
Correct |
143 ms |
6392 KB |
Output is correct |
17 |
Correct |
130 ms |
7100 KB |
Output is correct |
18 |
Correct |
142 ms |
7800 KB |
Output is correct |
19 |
Correct |
148 ms |
8312 KB |
Output is correct |
20 |
Correct |
191 ms |
9476 KB |
Output is correct |