Simple java solution
Complexity\n- Time complexity: O(n log n)\n\n- Space complexity: O(n)\n\n# Code\n\nclass Solution {\n    public int miceAndCheese(int[] reward1, int[] reward2, 
# Complexity\n- Time complexity: $$O(n log n)$$\n\n- Space complexity: $$O(n)$$\n\n# Code\n```\nclass Solution {\n    public int miceAndCheese(int[] reward1, int[] reward2, int k) {\n        List<Pair<Integer, Integer>> ans = new ArrayList<>();\n        for (int i = 0; i < reward1.length; i++) {\n            ans.add(new Pair<>(reward1[i] - reward2[i], i));\n        }\n        Collections.sort(ans, new Comparator<Pair<Integer, Integer>>() {\n            @Override\n            public int compare(Pair<Integer, Integer> o1, Pair<Integer, Integer> o2) {\n                return o2.getKey().compareTo(o1.getKey());\n            }\n        });\n        //Collections.sort(ans, Collections.reverseOrder());\n        int max = 0;\n        for (int i = 0; i < k; i++) {\n            max += reward1[ans.get(i).getValue()];\n        }\n        for (int i = k; i < ans.size(); i++) {\n            max += reward2[ans.get(i).getValue()];\n        }\n        return max;\n    }\n}\n```
['Java']