#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
//#define endl '\n'
llo n,m,s;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>m>>s;
vector<pair<llo,llo>> kk;
for(llo i=0;i<n;i++){
llo aa,bb;
cin>>aa>>bb;
kk.pb({aa,bb});
}
sort(kk.begin(),kk.end());
llo su=0;
reverse(kk.begin(),kk.end());
set<pair<llo,llo>> ss;
set<pair<llo,llo>> tt;
set<pair<llo,llo>> mm;
for(llo i=0;i<n;i++){
if(i<m){
su+=kk[i].a;
ss.insert({kk[i].a-kk[i].b,i});
}
else{
tt.insert({-kk[i].b,i});
mm.insert({-kk[i].a,i});
}
}
if(m==n){
cout<<su<<endl;
return 0;
}
for(llo i=0;i<s;i++){
llo x=-(*tt.begin()).a;
llo y=-(*ss.begin()).a-(*mm.begin()).a;
if(y>x or tt.size()==0){
su+=y;
ss.erase(ss.begin());
pair<llo,llo> no=*(mm.begin());
mm.erase(mm.begin());
mm.insert({kk[no.b].a-kk[no.b].b,no.b});
}
else{
pair<llo,llo> no=*(tt.begin());
tt.erase(tt.begin());
su+=-no.a;
}
}
cout<<su<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Incorrect |
5 ms |
256 KB |
Output isn't correct |
5 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
6 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
7 |
Incorrect |
7 ms |
896 KB |
Output isn't correct |
8 |
Incorrect |
7 ms |
768 KB |
Output isn't correct |
9 |
Incorrect |
7 ms |
768 KB |
Output isn't correct |
10 |
Incorrect |
7 ms |
768 KB |
Output isn't correct |
11 |
Incorrect |
8 ms |
1024 KB |
Output isn't correct |
12 |
Incorrect |
9 ms |
1024 KB |
Output isn't correct |
13 |
Incorrect |
31 ms |
3448 KB |
Output isn't correct |
14 |
Incorrect |
108 ms |
10732 KB |
Output isn't correct |
15 |
Correct |
239 ms |
22660 KB |
Output is correct |
16 |
Incorrect |
291 ms |
24288 KB |
Output isn't correct |
17 |
Incorrect |
223 ms |
25952 KB |
Output isn't correct |
18 |
Incorrect |
259 ms |
28516 KB |
Output isn't correct |
19 |
Incorrect |
274 ms |
31072 KB |
Output isn't correct |
20 |
Incorrect |
318 ms |
36564 KB |
Output isn't correct |