Easy Solution with explaination || C++
Approach\nfirst make the optimal choice by taking the maximum from both the array now check if number of target1s taking is greater or smaller than k if its gre
# Approach\nfirst make the optimal choice by taking the maximum from both the array now check if number of target1s taking is greater or smaller than k if its greater or smaller for that array of difference if the now for compernsating those extra values (extra than k) use then diff array to take those elements which contribute to least difference in the optimal answer like :-\n\nfor 4 4 2\n    6 1 1\nif k = 1 and we took index 1,2 from a so now for extra one element chosen make that diff array that is for 1,2 index element = [-3,-1]\nnow for that extra one element taken from take take 2 element that is contributing least negative value that is -1 and add it in optimal ans that is \n\noptimal ans = 6 + 4 + 2\n\nfinal ans = 6 + 4 + 2 - 1\n\n# Code\n```\nclass Solution {\npublic:\n    int miceAndCheese(vector<int>& reward1, vector<int>& reward2, int k) {\n        int n = reward1.size();\n        int ans = 0;\n        \n        vector<int> diffe , diffl;\n        int t1 = 0;\n        \n        for(int i=0;i<n;i++){\n            if(reward1[i] >= reward2[i]) {\n                ans += reward1[i];\n                diffl.push_back(reward2[i] - reward1[i]);\n                t1++;\n            }\n            else{\n                ans += reward2[i];\n                diffe.push_back(reward1[i] - reward2[i]);\n            }\n        }\n        sort(diffe.begin() , diffe.end() , greater<int>());\n        sort(diffl.begin() , diffl.end() , greater<int>());\n        cout<<ans<<endl;\n        \n        if(t1 < k) {\n            for(int i=0;i<(k-t1);i++) {\n                ans += diffe[i];\n            }\n            return ans;\n        }\n        \n        else if(t1 > k) {\n            for(int i=0;i<(t1-k);i++) {\n                ans += diffl[i];\n            }\n            return ans;\n        }\n        else return ans;\n    }\n};\n```
['C++']