#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAXN 300005
#define FOR(i, a, b) for(ll i = a; i <= b; i++)
ll n, t[2], pfx[MAXN], r = 0;
vector<array<ll, 2>> v(MAXN);
int main(){
cin >> n >> t[0] >> t[1];
FOR(i, 1, n) cin >> v[i][0] >> v[i][1];
sort(begin(v) + 1, begin(v) + 1 + n, [&](const auto &a, const auto &b) {
return a[0] - a[1] > b[0] - b[1];
});
priority_queue<ll> pq;
pfx[0] = 0;
FOR(i, 1, n){
pfx[i] = pfx[i - 1];
pfx[i] += v[i][0], pq.push(-v[i][0]);
while(pq.size() > t[0]) pfx[i] += pq.top(), pq.pop();
}
priority_queue<ll>().swap(pq);
ll sfx = 0;
for(int i = n; i >= 1; i--){
sfx += v[i][1];
pq.push(-v[i][1]);
while(pq.size() > t[1]) sfx += pq.top(), pq.pop();
if(pq.size() == t[1] && i - 1 >= t[1]) r = max(r, sfx + pfx[i - 1]);
}
cout << r << endl;
}
Compilation message
school.cpp: In function 'int main()':
school.cpp:23:25: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
23 | while(pq.size() > t[0]) pfx[i] += pq.top(), pq.pop();
| ~~~~~~~~~~^~~~~~
school.cpp:31:25: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
31 | while(pq.size() > t[1]) sfx += pq.top(), pq.pop();
| ~~~~~~~~~~^~~~~~
school.cpp:33:22: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
33 | if(pq.size() == t[1] && i - 1 >= t[1]) r = max(r, sfx + pfx[i - 1]);
| ~~~~~~~~~~^~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5156 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4956 KB |
Output isn't correct |
3 |
Correct |
2 ms |
5148 KB |
Output is correct |
4 |
Incorrect |
2 ms |
4952 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
4956 KB |
Output isn't correct |
6 |
Incorrect |
2 ms |
4956 KB |
Output isn't correct |
7 |
Correct |
3 ms |
5212 KB |
Output is correct |
8 |
Correct |
3 ms |
5212 KB |
Output is correct |
9 |
Correct |
5 ms |
5212 KB |
Output is correct |
10 |
Correct |
3 ms |
5212 KB |
Output is correct |
11 |
Incorrect |
4 ms |
5208 KB |
Output isn't correct |
12 |
Incorrect |
4 ms |
5208 KB |
Output isn't correct |
13 |
Correct |
17 ms |
6160 KB |
Output is correct |
14 |
Correct |
39 ms |
6844 KB |
Output is correct |
15 |
Correct |
73 ms |
8200 KB |
Output is correct |
16 |
Incorrect |
108 ms |
10660 KB |
Output isn't correct |
17 |
Incorrect |
125 ms |
11096 KB |
Output isn't correct |
18 |
Correct |
115 ms |
11488 KB |
Output is correct |
19 |
Correct |
128 ms |
11932 KB |
Output is correct |
20 |
Correct |
151 ms |
12760 KB |
Output is correct |