有大佬看看为什么答案错误,只过了 45 %,都没超时 public class Main { static long res = 0; static long[] nums; public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int k = scanner.nextInt(); nums = new long[n]; for (int i = 0; i < n; i++) { nums[i] = scanner.nextLong(); } Arrays.sort(nums); backtrack(nums.length, 0, 0, 0, 0, k); System.out.println(res); } private static void backtrack(long n, int cur, long sum, long total, long maxWeight, long k) { if (total != 0) { if (maxWeight * total <= sum * k) { res = Math.max(res, total); } else { return; } } if (cur == n) { return; } backtrack(n, cur + 1, sum + nums[cur], total + 1, Math.max(maxWeight, nums[cur]), k); backtrack(n, cur + 1, sum, total, maxWeight, k); } }