#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m,s,cnt=0,cnt1=0,p,q;
set <pair<int,pair <int,int> > > st,st1;
cin>>n>>m>>s;
int a[100001],b[100001];
for(int i=1;i<=n;i++){
cin>>a[i]>>b[i];
st.insert({-a[i],{i,1}});
st.insert({-b[i],{i,2}});
st1.insert({-a[i],{i,1}});
st1.insert({-b[i],{i,2}});
}
p=m; q=s;
while(m>=0 && s>=0){
if(s==0 && m==0) break;
pair<int,pair<int,int> > k=*st.begin();
if(k.second.second==1){
if(m>0) {
m--;
cnt+=(-k.first);
st.erase({-a[k.second.first],{k.second.first,1}});
st.erase({-b[k.second.first],{k.second.first,2}});
}
else{
st.erase(st.begin());
}
}
if(k.second.second==2){
if(s>0){
s--;
cnt+=(-k.first);
st.erase({-a[k.second.first],{k.second.first,1}});
st.erase({-b[k.second.first],{k.second.first,2}});
}
else{
st.erase(st.begin());
}
}
}
st1.erase(st1.begin());
m=p; s=q;
while(m>=0 && s>=0){
if(s==0 && m==0) break;
pair<int,pair<int,int> > k=*st1.begin();
if(k.second.second==1){
if(m>0) {
m--;
cnt1+=(-k.first);
st1.erase({-a[k.second.first],{k.second.first,1}});
st1.erase({-b[k.second.first],{k.second.first,2}});
}
else{
st1.erase(st1.begin());
}
}
if(k.second.second==2){
if(s>0){
s--;
cnt1+=(-k.first);
st1.erase({-a[k.second.first],{k.second.first,1}});
st1.erase({-b[k.second.first],{k.second.first,2}});
}
else{
st1.erase(st1.begin());
}
}
}
cout<<max(cnt,cnt1);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Execution timed out |
2025 ms |
476 KB |
Time limit exceeded |
3 |
Execution timed out |
2025 ms |
476 KB |
Time limit exceeded |
4 |
Incorrect |
2 ms |
476 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
476 KB |
Output isn't correct |
6 |
Incorrect |
2 ms |
476 KB |
Output isn't correct |
7 |
Incorrect |
13 ms |
1608 KB |
Output isn't correct |
8 |
Incorrect |
14 ms |
1756 KB |
Output isn't correct |
9 |
Incorrect |
13 ms |
1756 KB |
Output isn't correct |
10 |
Incorrect |
15 ms |
1756 KB |
Output isn't correct |
11 |
Incorrect |
14 ms |
1832 KB |
Output isn't correct |
12 |
Incorrect |
15 ms |
1848 KB |
Output isn't correct |
13 |
Incorrect |
161 ms |
9852 KB |
Output isn't correct |
14 |
Incorrect |
399 ms |
20656 KB |
Output isn't correct |
15 |
Runtime error |
417 ms |
53144 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
16 |
Runtime error |
412 ms |
53280 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
17 |
Runtime error |
370 ms |
53280 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
18 |
Runtime error |
344 ms |
53280 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
19 |
Runtime error |
399 ms |
53280 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
20 |
Runtime error |
346 ms |
53280 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |