#include <bits/stdc++.h>
using namespace std;
using ll=long long;
struct pii {
int a, b;
bool operator<(const pii b) const { return a>b.a; }
};
int main() {
ios::sync_with_stdio(0);cin.tie(0);
int N, X, Y;
cin>>N>>X>>Y;
vector<pii> A(N);
for(auto&[a,b]:A) cin>>a>>b;
sort(A.begin(), A.end());
for(int i=X; i<N; i++) swap(A[i].a, A[i].b);
sort(A.begin()+X, A.end());
priority_queue<int> Qa, Qb;
ll s=0;
for(int i=0; i<X+Y; i++) s+=A[i].a, (i<X ? Qa : Qb).push(A[i].b-A[i].a);
while(Qa.size() && Qb.size()) {
int a=Qa.top(); Qa.pop();
int b=Qb.top(); Qb.pop();
if(a+b<=0) break;
s+=a+b;
Qb.push(-a);
Qa.push(-b);
}
cout<<s<<'\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
7 |
Incorrect |
3 ms |
492 KB |
Output isn't correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Incorrect |
2 ms |
492 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
512 KB |
Output isn't correct |
11 |
Incorrect |
2 ms |
492 KB |
Output isn't correct |
12 |
Incorrect |
2 ms |
492 KB |
Output isn't correct |
13 |
Incorrect |
11 ms |
1260 KB |
Output isn't correct |
14 |
Incorrect |
28 ms |
2028 KB |
Output isn't correct |
15 |
Incorrect |
58 ms |
3436 KB |
Output isn't correct |
16 |
Correct |
70 ms |
4964 KB |
Output is correct |
17 |
Incorrect |
72 ms |
5740 KB |
Output isn't correct |
18 |
Incorrect |
72 ms |
6124 KB |
Output isn't correct |
19 |
Incorrect |
82 ms |
6508 KB |
Output isn't correct |
20 |
Incorrect |
90 ms |
7404 KB |
Output isn't correct |