#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define ld long double
// 217
// 44
using namespace std;
const int MAXN = (int) 3e5;
pair <int, int> arr[MAXN + 1];
bool cmp(pair <int, int> a, pair <int, int> b) {
/*if(a.first - a.second == b.first - b.second) {
return a.second < b.second;
}*/
return a.first - a.second > b.first - b.second;
}
ll pref[MAXN + 1], suff[MAXN + 1];
int main() {
//ifstream cin("A.in");
//ofstream cout("A.out");
int i, n, m, s;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m >> s;
for(i = 1; i <= n; i++) {
cin >> arr[i].first >> arr[i].second;
}
sort(arr + 1, arr + n + 1, cmp);
priority_queue <int> mst;
ll cur = 0;
for(i = 1; i <= n; i++) {
if(mst.size() < m) {
mst.push(-arr[i].first);
cur += arr[i].first;
}
else if(-(mst.top()) < arr[i].first) {
cur += mst.top();
mst.pop();
mst.push(-arr[i].first);
cur += arr[i].first;
}
pref[i] = cur;
}
while(!mst.empty()) {
mst.pop();
}
cur = 0;
for(i = n; i >= 1; i--) {
if(mst.size() < s) {
mst.push(-arr[i].second);
cur += arr[i].second;
}
else if(-(mst.top()) < arr[i].second) {
cur += mst.top();
mst.pop();
mst.push(-arr[i].second);
cur += arr[i].second;
}
suff[i] = cur;
}
ll ans = 0;
for(i = m; i <= n - s; i++) {
ans = max(ans, pref[i] + suff[i + 1]);
}
cout << ans;
//cin.close();
//cout.close();
return 0;
}
Compilation message
school.cpp: In function 'int main()':
school.cpp:38:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(mst.size() < m) {
~~~~~~~~~~~^~~
school.cpp:55:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(mst.size() < s) {
~~~~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
584 KB |
Output is correct |
4 |
Correct |
2 ms |
584 KB |
Output is correct |
5 |
Correct |
2 ms |
584 KB |
Output is correct |
6 |
Correct |
2 ms |
584 KB |
Output is correct |
7 |
Correct |
3 ms |
616 KB |
Output is correct |
8 |
Correct |
3 ms |
616 KB |
Output is correct |
9 |
Correct |
4 ms |
628 KB |
Output is correct |
10 |
Correct |
3 ms |
672 KB |
Output is correct |
11 |
Correct |
3 ms |
704 KB |
Output is correct |
12 |
Correct |
3 ms |
720 KB |
Output is correct |
13 |
Correct |
16 ms |
1744 KB |
Output is correct |
14 |
Correct |
28 ms |
2684 KB |
Output is correct |
15 |
Correct |
50 ms |
4352 KB |
Output is correct |
16 |
Correct |
67 ms |
5624 KB |
Output is correct |
17 |
Correct |
89 ms |
6260 KB |
Output is correct |
18 |
Correct |
90 ms |
6776 KB |
Output is correct |
19 |
Correct |
97 ms |
7208 KB |
Output is correct |
20 |
Correct |
112 ms |
8180 KB |
Output is correct |