✅ Difference Array | C++ | Sorting | Explanation | 🚀
Sort the array in desc order according to difference, remember we need the abs diff to maximise answer. Now start from max values and if more than k values are 
Sort the array in desc order according to difference, remember we need the abs diff to maximise answer. Now start from max values and if more than k values are present then we can choose the max of both rewards else we are bound to choose reward1 as we need k elements\n\nComplexity -> O(nlogn)\n\n```\nstruct data {\n    int a, b, diff ;\n};\nbool comp(struct data A, struct data B){\n    return A.diff > B.diff ;\n}\nclass Solution {\npublic:\n    \n    int miceAndCheese(vector<int>& reward1, vector<int>& reward2, int k) {\n        int n = reward1.size();\n        vector<struct data>v(n) ;\n        for(int i = 0 ; i < n;i++){\n            v[i].a = reward1[i];\n            v[i].b = reward2[i] ;\n            v[i].diff = abs(reward1[i] - reward2[i]);\n        }\n        sort(v.begin(), v.end(), comp);\n        int ans= 0 ;\n        for(int i = 0 ; i < n;i++){\n            if( k > 0){\n                if(n-i > k){\n                    ans += max(v[i].a, v[i].b);\n                    if(max(v[i].a, v[i].b) == v[i].a)\n                    k--;\n                }\n                else{\n                    ans += v[i].a;\n                    k--;\n                }\n                    \n            }\n            else\n                ans += v[i].b;\n        }\n        return ans;\n    }\n};\n```
['C', 'Sorting', 'C++']