Mice  and Cheese Easy way 🔮🎆🎆🔮🎁🎁🎁🎁
Intuition\n Describe your first thoughts on how to solve this problem. \nFirst Mice Should eat k cheese so we have to choose those cheese whose value v1  is gre
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFirst Mice Should eat k cheese so we have to choose those cheese whose value v1  is greater then v2  at particular index \n\nif not enough k cheese present whose value v1[i] >v2[i]  we have to pick cheese whose diff is min like v1[i]= 4 v2[i]= 5 so our loss min\n\n2nd Mice will eat all those cheese which first mice left  \n# Approach\n1. Create a vecotr<pair<int,int>> and a vector diff \n2. push diff and index in pair {v1-v2,i}\n3. sort the pair based on diff to reduce loss\n4. For Mice  1 ->\n5. pick first k element in pair whose diff is higher or min to (v1-v2)\n5. mark the index -1 as picked \n6. For Mice 2 ->\n7. Pick all those value whose index is not -1 in pair \n8. return res \n<!-- Describe your approach to solving the problem. -->\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n log n)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(n)\n# Code\n```cpp []\n/*\nFirst Mice Should it k cheese so we have to choose those chease whose value v1  is greater then v2 \n// if no enough k cheese present whose value v1[i] >v2[i]  we have to pick cheese whose diff is min like v1[i]= 4 v2[i]= 5 so our loss min\n// 2nd Mice will eat all those cheese which first mice left  \n*/\nbool comp(pair<int,int>&a,pair<int,int>&b)\n{\n    return a.first>b.first;\n}\nclass Solution \n{\npublic:\nint miceAndCheese(vector<int>& v1, vector<int>& v2, int k) \n{\n    vector<int>diff;\n    vector<pair<int,int>>p;\n    for(int i=0;i<v1.size();i++)\n    {\n        p.push_back(make_pair(v1[i]-v2[i],i));\n    }\n    sort(p.begin(),p.end(),comp);\n    int res=0;\n    int i=0;\n    while(k!=0)\n    {\n        res=res+v1[p[i].second];\n        k=k-1;\n        p[i].second=-1;\n        i=i+1;\n    }\n    for(int i=0;i<p.size();i++)\n    {\n        if(p[i].second!=-1)\n        {\n            res=res+v2[p[i].second];\n            p[i].second=-1;\n        }\n    }\n    return res;\n    }\n};\n```
['C++']