LC.P2611[老鼠和奶酪] 方法一:贪心+排序1234567891011121314class Solution { public int miceAndCheese(int[] reward1, int[] reward2, int k) { int ans = 0, n = reward1.length; for (int i = 0; i < n; ++i) { ans += reward2[i]; reward1[i] -= reward2[i]; } Arrays.sort(reward1); for (int i = 0; i < k; ++i) { ans += reward1[n - i - 1]; } return ans; }} 时间复杂度:$O(nlogn)$ 空间复杂度:$O(n)$