Greedy
\n\n# Code\n\nclass Solution {\npublic:\n    int miceAndCheese(vector<int>& reward1, vector<int>& reward2, int k) {\n        int n = reward1.size(),res = 0;\n  
\n\n# Code\n```\nclass Solution {\npublic:\n    int miceAndCheese(vector<int>& reward1, vector<int>& reward2, int k) {\n        int n = reward1.size(),res = 0;\n        \n        //maximum diff \n        vector<vector<int>> diff(n);\n        for (int i = 0; i < n; i++)diff[i] = {reward1[i] - reward2[i], i};\n        \n        //sort and take vis array\n        vector<int> vis(n);\n        sort(diff.rbegin(), diff.rend());\n        \n        // take points from rewards\n        for(int i= 0;i<k;i++)  res += reward1[diff[i][1]],vis[diff[i][1]] = 1;\n        for(int i= 0;i<reward2.size();i++)if(!vis[i])res+=reward2[i];\n        \n        // we got the answer\n        return res;\n    }\n};\n```
['C++']