Java 版本: public class T1Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { // 封装值 String str = scanner.nextLine(); Integer total = scanner.nextInt(); Set<Integer> ws = new TreeSet<>(); for (String item : str.split(",")) { ws.add(Integer.parseInt(item)); } // 简单贪心算法 Integer num = 0; Integer c = 0; for (Integer w : ws) { c += w; if (c > total) { break; } num++; } System.out.println(num); } } }
点赞 评论

相关推荐

05-09 13:22
门头沟学院 Java
点赞 评论 收藏
分享
Ncsbbss:又想干活又想要工资,怎么什么好事都让你占了
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务