結果
問題 |
No.156 キャンディー・ボックス
|
ユーザー |
![]() |
提出日時 | 2015-12-29 15:19:11 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 113 ms / 2,000 ms |
コード長 | 645 bytes |
コンパイル時間 | 3,771 ms |
コンパイル使用メモリ | 84,496 KB |
実行使用メモリ | 41,488 KB |
最終ジャッジ日時 | 2024-07-05 15:46:32 |
合計ジャッジ時間 | 7,458 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
import java.util.LinkedList; class A { int want; LinkedList<Integer> have = new LinkedList<Integer>(); A(int i) { this.want = i; } } public class No_156 { public static void main(String[] args) { java.util.Scanner sc = new java.util.Scanner(System.in); int n = sc.nextInt(); LinkedList<Integer> box = new LinkedList<Integer>(); A a = new A(sc.nextInt()); for (int i = 0; i < n; i++) { box.add(sc.nextInt()); } java.util.Collections.sort(box); while (a.want > 0) { int x = box.poll(); a.want -= x; if (a.want >= 0) { a.have.add(x); } } System.out.println(a.have.size()); sc.close(); } }