#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define nyan "(=^・ω・^=)"
#define read_input freopen("in.txt","r", stdin)
#define print_output freopen("out.txt","w", stdout)
typedef long long ll;
typedef long double ld;
using namespace std;
const int maxn = 3e5+10;
ll f1[maxn], f2[maxn];
int main()
{
pii a[maxn];
int n, A, B;
cin >> n >> A >> B;
for(int i = 1; i <= n; i++) {
cin >> a[i].first >> a[i].second;
}
sort(a+1, a+n+1, [] (pii a, pii b) -> bool {return a.first - a.second > b.first - b.second;});
priority_queue<int, vector<int>, greater<int>> pq;
ll sum = 0;;
for(int i = 1; i <= n; i++) {
sum += a[i].first;
pq.push(a[i].first);
if(pq.size() > A) {
sum -= pq.top();
pq.pop();
}
f1[i] = sum;
}
while(! pq.empty()) pq.pop(); sum = 0;
for(int i = n; i >= 1; i--) {
sum += a[i].second;
pq.push(a[i].second);
if(pq.size() > B) {
sum -= pq.top();
pq.pop();
}
f2[i] = sum;
}
ll mx = 0;
for(int i = A; i <= n-B; i++)
mx = max(mx, f1[i] + f2[i+1]);
cout << mx << endl;
return 0;
}
Compilation message
school.cpp: In function 'int main()':
school.cpp:33:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(pq.size() > A) {
~~~~~~~~~~^~~
school.cpp:39:2: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
while(! pq.empty()) pq.pop(); sum = 0;
^~~~~
school.cpp:39:32: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
while(! pq.empty()) pq.pop(); sum = 0;
^~~
school.cpp:45:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(pq.size() > B) {
~~~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2816 KB |
Output is correct |
2 |
Correct |
3 ms |
2688 KB |
Output is correct |
3 |
Correct |
4 ms |
2688 KB |
Output is correct |
4 |
Correct |
4 ms |
2688 KB |
Output is correct |
5 |
Correct |
3 ms |
2688 KB |
Output is correct |
6 |
Correct |
3 ms |
2688 KB |
Output is correct |
7 |
Correct |
7 ms |
2816 KB |
Output is correct |
8 |
Correct |
8 ms |
2944 KB |
Output is correct |
9 |
Correct |
8 ms |
2816 KB |
Output is correct |
10 |
Correct |
8 ms |
2816 KB |
Output is correct |
11 |
Correct |
7 ms |
2816 KB |
Output is correct |
12 |
Correct |
8 ms |
2816 KB |
Output is correct |
13 |
Correct |
33 ms |
3864 KB |
Output is correct |
14 |
Correct |
63 ms |
5084 KB |
Output is correct |
15 |
Correct |
117 ms |
7020 KB |
Output is correct |
16 |
Correct |
137 ms |
8332 KB |
Output is correct |
17 |
Correct |
178 ms |
9228 KB |
Output is correct |
18 |
Correct |
199 ms |
9740 KB |
Output is correct |
19 |
Correct |
211 ms |
10468 KB |
Output is correct |
20 |
Correct |
242 ms |
11504 KB |
Output is correct |