#include<bits/stdc++.h>
#define ss second
#define pb push_back
#define mp make_pair
#define ff first
using namespace std;
int n,m,s;
vector<pair<int,int> > dp,dp1;
int main(){
cin >> n >> m >> s;
for(int i=1;i<=n;i++){
int x,y;
cin >> x >> y;
dp.pb(mp(x,i));
dp1.pb(mp(y,i));
}
sort(dp.begin(),dp.end());
sort(dp1.begin(),dp1.end());
int res=0;
for(int i=n-1;i>=0;i--){
if(m>0&&s>0){
if(dp[i].ss!=dp1[i].ss){
m--;
s--;
res+=dp[i].ff;
res+=dp1[i].ff;
}
else{
if(dp[i-1].ff+dp1[i].ff>dp1[i-1].ff+dp[i].ff){
res+=dp[i-1].ff;
res+=dp1[i].ff;
i--;
m--;
s--;
}
else{
res+=dp1[i-1].ff;
res+=dp[i].ff;
i--;
m--;
s--;
}
}
}
if(m>0&&s==0){
res+=dp[i].ff;
m--;
}
if(m==0&&s>0){
res+=dp1[i].ff;
s--;
}
if(m<0&&s<0) break;
}
cout << res;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
4 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
6 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
7 |
Incorrect |
7 ms |
504 KB |
Output isn't correct |
8 |
Incorrect |
7 ms |
504 KB |
Output isn't correct |
9 |
Incorrect |
7 ms |
504 KB |
Output isn't correct |
10 |
Incorrect |
8 ms |
504 KB |
Output isn't correct |
11 |
Incorrect |
8 ms |
504 KB |
Output isn't correct |
12 |
Incorrect |
8 ms |
504 KB |
Output isn't correct |
13 |
Incorrect |
45 ms |
1660 KB |
Output isn't correct |
14 |
Incorrect |
95 ms |
2920 KB |
Output isn't correct |
15 |
Incorrect |
195 ms |
5316 KB |
Output isn't correct |
16 |
Incorrect |
223 ms |
5420 KB |
Output isn't correct |
17 |
Incorrect |
282 ms |
6764 KB |
Output isn't correct |
18 |
Incorrect |
306 ms |
7256 KB |
Output isn't correct |
19 |
Incorrect |
335 ms |
7732 KB |
Output isn't correct |
20 |
Incorrect |
391 ms |
10080 KB |
Output isn't correct |