Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- long long getm(long long k,vector<long long>r1,vector<long long>r2){
- long long rem = r1.size() - k;
- long long n = r1.size();
- vector<pair<long long,long long>>vp;
- for(long long i=0;i<n;i++){
- vp.push_back({abs(r1[i]-r2[i]),i});
- }
- sort(vp.begin(),vp.end());
- long long tt = 0;
- for(long long i=n-1;i>=0;i--){
- long long in = vp[i].second;
- if(r1[in]>r2[in]){
- if(k!=0){
- tt += r1[in];
- k--;
- }
- else {
- tt += r2[in];
- rem--;
- }
- }
- else{
- if(rem!=0){
- tt += r2[in];
- rem--;
- }
- else {
- tt += r1[in];
- k--;
- }
- }
- }
- return tt;
- }
Add Comment
Please, Sign In to add comment