#include <bits/stdc++.h>
using namespace std;
#define type(x) __typeof((x).begin())
#define foreach(it, x) for(type(x) it = (x).begin(); it != (x).end(); it++)
typedef long long ll;
typedef pair < int, int > ii;
const int inf = 1e9 + 333;
const ll linf = 1e18 + inf;
const int N = 3e5 + 5;
int n, m, s;
ii a[N];
int main() {
scanf("%d %d %d", &n, &m, &s);
for(int i = 1; i <= n; i++) {
scanf("%d %d", &a[i].second, &a[i].first);
}
sort(a + 1, a + n + 1);
reverse(a + 1, a + n + 1);
for(int i = 1; i <= n; i++)
swap(a[i].first, a[i].second);
ll sum = 0, add = 0, ans = 0;
set < ii > s1, s2;
for(int i = 1; i < s; i++) {
sum += a[i].second;
s1.insert(ii(a[i].first - a[i].second, i));
}
for(int i = s + 1; i <= n; i++) {
s2.insert(ii(a[i].first, i));
}
while(s2.size() > m + 1) {
s2.erase(*s2.begin());
}
foreach(it, s2) {
add += it -> first;
}
for(int i = s; ; i++) {
if(!s2.size())
break;
if(s2.find(ii(a[i].first, i)) == s2.end()) {
add -= s2.begin() -> first;
s2.erase(s2.begin());
}
else {
add -= a[i].first;
s2.erase(ii(a[i].first, i));
}
ll res = sum + add + a[i].second;
ans = max(ans, res);
//printf("i = %d res = %lld ans = %lld\n", i, res, ans);
//printf("sum = %d add = %d\n", sum, add);
ii best = s1.size() ? *s1.rbegin() : ii(0, 0);
if(!s1.size() or a[i].first > a[i].second + best.first) {
sum += a[i].first;
}
else {
sum += a[i].second + best.first;
s1.erase(*s1.rbegin());
s1.insert(ii(a[i].first - a[i].second, i));
}
}
printf("%lld\n", ans);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
4068 KB |
Output isn't correct |
2 |
Correct |
2 ms |
4068 KB |
Output is correct |
3 |
Incorrect |
2 ms |
4068 KB |
Output isn't correct |
4 |
Correct |
0 ms |
4068 KB |
Output is correct |
5 |
Correct |
0 ms |
4068 KB |
Output is correct |
6 |
Correct |
0 ms |
4068 KB |
Output is correct |
7 |
Correct |
2 ms |
4200 KB |
Output is correct |
8 |
Incorrect |
0 ms |
4200 KB |
Output isn't correct |
9 |
Correct |
3 ms |
4200 KB |
Output is correct |
10 |
Correct |
0 ms |
4200 KB |
Output is correct |
11 |
Correct |
2 ms |
4200 KB |
Output is correct |
12 |
Correct |
5 ms |
4200 KB |
Output is correct |
13 |
Correct |
42 ms |
5652 KB |
Output is correct |
14 |
Correct |
71 ms |
7632 KB |
Output is correct |
15 |
Correct |
144 ms |
11460 KB |
Output is correct |
16 |
Incorrect |
180 ms |
12384 KB |
Output isn't correct |
17 |
Correct |
240 ms |
14232 KB |
Output is correct |
18 |
Correct |
276 ms |
15288 KB |
Output is correct |
19 |
Correct |
266 ms |
16212 KB |
Output is correct |
20 |
Correct |
337 ms |
18060 KB |
Output is correct |