Very Easy to understand Intuitive approach | Minimal code | C ++
Intuition\n Describe your first thoughts on how to solve this problem. \nAn important thing to notice is that both mice will try to maximize their scores. There
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAn important thing to notice is that both mice will try to maximize their scores. Therefore the absolute value of the differences of their scores (mouse1_score - mouse2_score) should be minimum. So for the first mouse we pick the k cheeses such that the difference is the maximum and for the second mouse we pick n-k cheeses such that the difference is minimum.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe sort the array by the difference of reward points.\n\n# Complexity\n- Time complexity: O(nlogn)\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# Generalized Version \nMouse 1 picks k1 items and mouse2 picks k2 items such that k1+k2<=n. See comments.\n\n# Code\n```\nclass Solution {\npublic:\n    int miceAndCheese(vector<int>& reward1, vector<int>& reward2, int k) {\n        int n = reward1.size();\n        vector<pair<int,int>> t;\n      for(int i=0;i<n;++i){\n          t.push_back({reward1[i],reward2[i]});\n      }\n      sort(t.begin(),t.end(),[](auto &p1, auto &p2){\n          return p1.first - p1.second > p2.first - p2.second;\n      });\n      int ans = 0;\n      for(int i=0;i<n;i++){\n          if(i<k)\n            ans+=t[i].first;\n          else\n            ans+=t[i].second;\n      }\n      return ans;\n    }  \n};\n```
['C++']