public static void main(String[] args) { List<Integer> tax = new ArrayList<>(); tax.add(70); tax.add(55); tax.add(40); tax.add(30); tax.add(20); tax.add(10); // 关税倒序排列 Collections.sort(tax, new Comparator<Integer>() { @Override public int compare(Integer o1, Integer o2) { return o2.compareTo(o1); } }); int bagCnt = 0; int taxSum = 0; int bagLmt = 50; for (Integer t : tax) { if (t >= bagLmt) { bagCnt++; taxSum = 0; } else { if (taxSum + t > bagLmt) { bagCnt++; taxSum = t; } else { taxSum += t; } } } if(taxSum >0) bagCnt++; System.out.println(bagCnt); }