I'm So GREEDY!
Time Complexity: O(n * logn)\nSpace Complexity: O(n) (if you do the ar work in reward1 or reward2 array itself it\'ll be O(1))\nNow,\nUpvote [^] wish me some lu
**Time Complexity: O(n * logn)**\n**Space Complexity: O(n)** (*if you do the ar work in reward1 or reward2 array itself it\'ll be O(1)*)\nNow,\n**Upvote [^]** *wish me some luck!*\n\n```class Solution {\n    public int miceAndCheese(int[] reward1, int[] reward2, int k) {\n        int n = reward1.length;\n        int ans = 0;\n        int[] ar = new int[n];\n        for(int i = 0; i < n; i++){\n            ar[i] = reward1[i]-reward2[i];\n            ans += reward2[i];  // adding all of reward2 to ans\n        }\n        \n\t\t// sorting the array\n        Arrays.sort(ar);\n        System.out.println(Arrays.toString(ar));\n\t\t\n\t\t// Adding the last k because it\'s sorted in asc order & we need largest elements\n\t\t// so k elements from reward2 will be converted to reward1\'s element\n        for(int i = 0; i < k; i++){\n\t\t\tans += ar[n-1-i];    \n        }\n\t\t\n        return ans;\n    }\n}\n```
['Java']