Easy C++
Approach\n Describe your approach to solving the problem. \n1. Storing difference and both rewards in new vector.\n2. Then sorting on basis of difference.\n3. T
# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Storing difference and both rewards in new vector.\n2. Then sorting on basis of difference.\n3. Top k element with highest difference taking reward1 in ans and other as reward2.\n\n# Complexity\n- Time complexity: $$O(n*Log(n))$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int miceAndCheese(vector<int>& r1, vector<int>& r2, int k) {\n        int n=r1.size(),ans=0;\n        vector<vector<int>> x(n,vector<int>(3,0));\n        for(int i=0;i<n;i++) x[i]={r1[i]-r2[i],r1[i],r2[i]};\n        sort(x.begin(),x.end());\n        for(int i=0;i<n;i++){\n            if(i>=n-k) ans+=x[i][1];\n            else ans+=x[i][2];\n        }\n        return ans;\n    }\n};\n```
['Sorting', 'C++']