#include <bits/stdc++.h>
using namespace std;
struct area{
int a, b;
};
int main(){
int N, M, S;
cin >> N >> M >> S;
vector<area> A;
for(int i = 0; i < N; i++){
int a, b; cin >> a >> b;
A.push_back({a, b});
}
sort(A.begin(), A.end(), [](area x, area y){
return x.a > y.a;
});
int ans = 0;
for(int i = 0; i < M; i++){
ans += A[i].a;
}
priority_queue<pair<int, int>> pq1, pq2;
for(int i = 0; i < M; i++){
pq1.push({A[i].b - A[i].a, i});
}
for(int i = M; i < N; i++){
pq2.push({A[i].b, i});
}
for(int i = 0; i < S; i++){
if(pq2.empty() || !pq1.empty() && pq1.top().first + A[M + i].a > pq2.top().first){
ans += pq1.top().first + A[M + i].a;
pq1.pop();
}else{
ans += pq2.top().first;
pq2.pop();
}
}
cout << ans << endl;
}
Compilation message
school.cpp: In function 'int main()':
school.cpp:35:34: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
35 | if(pq2.empty() || !pq1.empty() && pq1.top().first + A[M + i].a > pq2.top().first){
| ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
7 |
Incorrect |
3 ms |
468 KB |
Output isn't correct |
8 |
Incorrect |
3 ms |
468 KB |
Output isn't correct |
9 |
Incorrect |
3 ms |
340 KB |
Output isn't correct |
10 |
Incorrect |
3 ms |
444 KB |
Output isn't correct |
11 |
Incorrect |
4 ms |
468 KB |
Output isn't correct |
12 |
Incorrect |
4 ms |
468 KB |
Output isn't correct |
13 |
Incorrect |
21 ms |
1444 KB |
Output isn't correct |
14 |
Incorrect |
50 ms |
3324 KB |
Output isn't correct |
15 |
Incorrect |
93 ms |
6260 KB |
Output isn't correct |
16 |
Incorrect |
126 ms |
7032 KB |
Output isn't correct |
17 |
Incorrect |
138 ms |
8360 KB |
Output isn't correct |
18 |
Incorrect |
146 ms |
8912 KB |
Output isn't correct |
19 |
Incorrect |
160 ms |
9336 KB |
Output isn't correct |
20 |
Incorrect |
195 ms |
10460 KB |
Output isn't correct |