[C++] sort by difference
Intuition\njust sort by difference of ith rewards(1&2)\nuse first reward till k and then use 2nd rewards\n# Code\n\nbool cmp(pair <int,int>a,pair <int,int>b)\n 
# Intuition\njust sort by difference of ith rewards(1&2)\nuse first reward till k and then use 2nd rewards\n# Code\n```\nbool cmp(pair <int,int>a,pair <int,int>b)\n    return (a.first-a.second)>(b.first-b.second);\nclass Solution {\npublic:\n    int miceAndCheese(vector<int>& r, vector<int>& s, int k) {\n        vector<pair <int,int>> v;\n        int n=r.size();\n        for(int i=0;i<n;i++)\n        {\n            v.push_back({r[i],s[i]});\n        }\n        sort(v.begin(),v.end(),cmp);\n        int sum=0;\n        for(int i=0;i<n;i++)\n        {\n            if(i<k) sum+=v[i].first;\n            else sum+=v[i].second;\n        }\n        return sum;\n    }\n};\n```
['C++']