#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pq priority_queue
#define in pair<int, int>
#define f first
#define s second
#define pb push_back
#define pob pop_back
#define INF (int)1e17
#define MX (int)3e5+5
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL)
struct ritul
{
int Limit;
int sz;
int sum;
pq<int> chungus;
void init(int x)
{
Limit = x;
sz = 0;
while(!chungus.empty())
chungus.pop();
sum = 0;
return;
}
void push(int x)
{
chungus.push(-x);
sz++;
sum+=x;
if(sz > Limit)
{
sum+=chungus.top();
sz--;
chungus.pop();
}
return;
}
int ans()
{
return sum;
}
};
signed main()
{
fast(); ritul work;
int n, A, B; cin >> n >> A >> B;
vector<int> a(n+1), b(n+1), d(n+1, 0), e(n+1, 0); vector<in> c(n+1);
for(int i = 1; i <= n; i++)
{
cin >> a[i] >> b[i];
c[i] = {b[i]-a[i], i};
}
c[0] = {-INF, -INF};
sort(c.begin(), c.end());
work.init(A);
for(int i = 1; i <= n; i++)
{
work.push(a[c[i].s]);
d[i] = work.ans();
}
work.init(B);
for(int i = n; i >= 1; i--)
{
work.push(b[c[i].s]);
e[i] = work.ans();
}
int ans = -1;
for(int i = A; i <= n-B; i++)
ans = max(ans, d[i]+e[i+1]);
cout << ans << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
376 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
744 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
2 ms |
704 KB |
Output is correct |
12 |
Correct |
2 ms |
600 KB |
Output is correct |
13 |
Correct |
12 ms |
2528 KB |
Output is correct |
14 |
Correct |
24 ms |
4444 KB |
Output is correct |
15 |
Correct |
43 ms |
7900 KB |
Output is correct |
16 |
Correct |
56 ms |
10956 KB |
Output is correct |
17 |
Correct |
78 ms |
11732 KB |
Output is correct |
18 |
Correct |
90 ms |
12900 KB |
Output is correct |
19 |
Correct |
96 ms |
13552 KB |
Output is correct |
20 |
Correct |
109 ms |
15568 KB |
Output is correct |