Simple Java solution
This solution implements the logic used by lee215 in his approach. \nStep1 : Assume we select all the elements in reward 2.\nStep2: Now, we wanted to select k f
This solution implements the logic used by lee215 in his approach. \nStep1 : Assume we select all the elements in reward 2.\nStep2: Now, we wanted to select k from reward1 so, lets pick those k elements from reward1 which are highest from their corresponding values in reward2 on the same index. In other words, just pick those elements who differ from their corresponding reward2 by max amount and add them. Now, note that since we already added the reward2 values into the answer, we just need to add the differnece of these elements. \nTo implement step2 just create a heap of size k containing k maximum differences between reward1 and reward 2 elements at any given index.\n    \n\tclass Solution {\n        public int miceAndCheese(int[] reward1, int[] reward2, int k) {\n            int ans = 0;\n            for(int i : reward2) ans+=i;\n\n            PriorityQueue<Integer> minHeap = new PriorityQueue();\n            for(int i=0; i<reward1.length; i++) {\n                minHeap.offer(reward1[i] - reward2[i]);\n                if(minHeap.size()>k) minHeap.poll();\n            }\n            while(!minHeap.isEmpty) ans += minHeap.poll();\n\n            return ans;\n        }\n    }
['Java']