# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
164500 | itgl | Schools (IZhO13_school) | C++14 | 391 ms | 10080 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |