#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);
multiset <int> mst;
ll cur = 0;
for(i = 1; i <= n; i++) {
if(mst.size() < m) {
mst.insert(arr[i].first);
cur += arr[i].first;
}
else if(*mst.begin() < arr[i].first) {
cur -= *mst.begin();
mst.erase(mst.begin());
mst.insert(arr[i].first);
cur += arr[i].first;
}
pref[i] = cur;
}
mst.clear();
cur = 0;
for(i = n; i >= 1; i--) {
if(mst.size() < s) {
mst.insert(arr[i].second);
cur += arr[i].second;
}
else if(*mst.begin() < arr[i].second) {
cur -= *mst.begin();
mst.erase(mst.begin());
mst.insert(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:53:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(mst.size() < s) {
~~~~~~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Execution timed out |
2048 ms |
376 KB |
Time limit exceeded |
3 |
Correct |
2 ms |
448 KB |
Output is correct |
4 |
Correct |
2 ms |
592 KB |
Output is correct |
5 |
Correct |
2 ms |
592 KB |
Output is correct |
6 |
Correct |
2 ms |
592 KB |
Output is correct |
7 |
Correct |
3 ms |
628 KB |
Output is correct |
8 |
Correct |
3 ms |
800 KB |
Output is correct |
9 |
Correct |
4 ms |
800 KB |
Output is correct |
10 |
Correct |
4 ms |
800 KB |
Output is correct |
11 |
Correct |
4 ms |
800 KB |
Output is correct |
12 |
Correct |
4 ms |
816 KB |
Output is correct |
13 |
Correct |
22 ms |
2864 KB |
Output is correct |
14 |
Correct |
38 ms |
3376 KB |
Output is correct |
15 |
Correct |
51 ms |
4528 KB |
Output is correct |
16 |
Correct |
140 ms |
12328 KB |
Output is correct |
17 |
Correct |
173 ms |
12328 KB |
Output is correct |
18 |
Correct |
163 ms |
12328 KB |
Output is correct |
19 |
Correct |
185 ms |
12328 KB |
Output is correct |
20 |
Correct |
209 ms |
12972 KB |
Output is correct |