C++ || USING HEAD || EASY TO UNDERSTAND
In question given that first rat eat k item.and remaing items eat rat2. there is no constraint that rat1 eat only these items.\nso rat1 eat those item which hav
In question given that first rat eat k item.and remaing items eat rat2. there is no constraint that rat1 eat only these items.\nso rat1 eat those item which have maximum diffrence (mean (v1[i]-v2[i]) > (v1[j]>v2[j]) than eat i item).\n\n# Complexity\n- Time complexity:\nO(nlogk)\n\n- Space complexity:\nO(k)\n\n# Code\n```\nclass Solution {\npublic:\n    int miceAndCheese(vector<int>& reward1, vector<int>& reward2, int k) {\n        int ans = 0;\n        priority_queue<int,vector<int>,greater<int>> pq;\n        for(int i = 0; i < reward1.size(); i++){\n            ans += reward2[i];\n            ans += (reward1[i]-reward2[i]);\n            pq.push(reward1[i]-reward2[i]);\n            if(pq.size()>k){\n                ans -= pq.top();\n                pq.pop();\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']