結果

問題 No.156 キャンディー・ボックス
ユーザー atkrymatkrym
提出日時 2016-10-24 00:28:45
言語 Java21
(openjdk 21)
結果
AC  
実行時間 132 ms / 2,000 ms
コード長 678 bytes
コンパイル時間 3,066 ms
コンパイル使用メモリ 73,220 KB
実行使用メモリ 57,872 KB
最終ジャッジ日時 2023-09-19 03:16:06
合計ジャッジ時間 8,235 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
55,644 KB
testcase_01 AC 131 ms
55,796 KB
testcase_02 AC 129 ms
55,392 KB
testcase_03 AC 130 ms
55,636 KB
testcase_04 AC 129 ms
55,808 KB
testcase_05 AC 130 ms
55,448 KB
testcase_06 AC 130 ms
55,412 KB
testcase_07 AC 129 ms
55,532 KB
testcase_08 AC 131 ms
55,440 KB
testcase_09 AC 128 ms
55,644 KB
testcase_10 AC 129 ms
55,300 KB
testcase_11 AC 130 ms
55,456 KB
testcase_12 AC 130 ms
55,748 KB
testcase_13 AC 128 ms
55,668 KB
testcase_14 AC 130 ms
55,824 KB
testcase_15 AC 132 ms
55,792 KB
testcase_16 AC 129 ms
55,432 KB
testcase_17 AC 128 ms
55,304 KB
testcase_18 AC 131 ms
55,172 KB
testcase_19 AC 129 ms
55,520 KB
testcase_20 AC 129 ms
55,168 KB
testcase_21 AC 130 ms
55,420 KB
testcase_22 AC 130 ms
55,440 KB
testcase_23 AC 128 ms
55,316 KB
testcase_24 AC 128 ms
55,800 KB
testcase_25 AC 128 ms
57,872 KB
testcase_26 AC 128 ms
55,876 KB
testcase_27 AC 131 ms
55,408 KB
testcase_28 AC 128 ms
55,208 KB
testcase_29 AC 129 ms
55,488 KB
testcase_30 AC 129 ms
55,568 KB
testcase_31 AC 132 ms
55,472 KB
testcase_32 AC 132 ms
55,636 KB
testcase_33 AC 132 ms
55,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    private static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        int n = sc.nextInt();
        int m = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for (int i = 0;i < n;i++) {
            list.add(sc.nextInt());
        }
        
        Collections.sort(list);

        int ret = 0;
        for (int i = 0;i < n;i++) {
            int num = list.get(i);
            if (num <= m) {
                ret++;
                m -= num;
            } else {
                break;
            }
        }
        
        System.out.println(ret);
    }
}
0