NlogK | Greedy | Hashing | Heap
Approch: Greedy: Pick the maximum cheese for mouse1 and rest for mouse2\n\n// TC: O(NlogK)\n// SC: O(K)\n#define ll long long\nclass Solution {\npublic:\n    in
**Approch: Greedy: Pick the maximum cheese for mouse1 and rest for mouse2**\n```\n// TC: O(NlogK)\n// SC: O(K)\n#define ll long long\nclass Solution {\npublic:\n    int miceAndCheese(vector<int>& arr1, vector<int>& arr2, int k){\n        int n = arr1.size();\n        priority_queue<pair<int, int>, vector<pair<int, int>>,greater<pair<int, int>>> pq;\n        \n        for(int i = 0; i < n; i++){\n            pq.push({arr1[i] - arr2[i], i});\n            if(pq.size() > k){\n                pq.pop();\n            }\n        }\n        \n        unordered_set<int> set;\n        while(pq.size()){\n            set.insert(pq.top().second);\n            pq.pop();\n        }\n        \n        ll ans = 0;\n        for(int i = 0; i < n; i++){\n            if(set.count(i)){\n                ans += arr1[i];\n            }else{\n                ans += arr2[i];\n            }\n        }\n        return ans;\n    }\n};\n```
['Greedy', 'Heap (Priority Queue)']