結果

問題 No.156 キャンディー・ボックス
ユーザー samplelpmassamplelpmas
提出日時 2016-11-10 13:14:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 825 bytes
コンパイル時間 2,345 ms
コンパイル使用メモリ 72,504 KB
実行使用メモリ 56,184 KB
最終ジャッジ日時 2023-09-19 03:16:55
合計ジャッジ時間 8,033 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
55,712 KB
testcase_01 AC 130 ms
55,584 KB
testcase_02 AC 127 ms
55,364 KB
testcase_03 AC 128 ms
55,488 KB
testcase_04 AC 127 ms
55,220 KB
testcase_05 AC 128 ms
55,928 KB
testcase_06 AC 128 ms
55,372 KB
testcase_07 AC 131 ms
54,076 KB
testcase_08 AC 130 ms
55,244 KB
testcase_09 AC 128 ms
55,596 KB
testcase_10 AC 128 ms
55,688 KB
testcase_11 AC 130 ms
55,584 KB
testcase_12 AC 130 ms
55,532 KB
testcase_13 AC 129 ms
55,492 KB
testcase_14 AC 128 ms
55,668 KB
testcase_15 AC 131 ms
55,716 KB
testcase_16 AC 129 ms
53,668 KB
testcase_17 AC 129 ms
55,476 KB
testcase_18 AC 130 ms
55,680 KB
testcase_19 AC 134 ms
55,360 KB
testcase_20 AC 130 ms
55,652 KB
testcase_21 AC 129 ms
55,676 KB
testcase_22 AC 129 ms
55,744 KB
testcase_23 AC 129 ms
55,896 KB
testcase_24 AC 126 ms
55,628 KB
testcase_25 AC 127 ms
55,492 KB
testcase_26 AC 126 ms
55,592 KB
testcase_27 AC 129 ms
55,668 KB
testcase_28 AC 129 ms
55,540 KB
testcase_29 AC 127 ms
55,364 KB
testcase_30 AC 129 ms
55,832 KB
testcase_31 AC 131 ms
56,184 KB
testcase_32 AC 128 ms
55,576 KB
testcase_33 AC 128 ms
55,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int numBoxes = sc.nextInt();
        int takingCandyTotal = sc.nextInt();
        int[] numCandies = new int[numBoxes];

        for (int i = 0; i < numBoxes; i++) {
            numCandies[i] = sc.nextInt();
        }

        Arrays.sort(numCandies);

        int numEmptyBoxes = 0;

        for (int i = 0; i < numBoxes; i++) {

            int numTakingCandy = Math.min(takingCandyTotal, numCandies[i]);

            numCandies[i] -= numTakingCandy;
            takingCandyTotal -= numTakingCandy;

            if (numCandies[i] == 0) {
                numEmptyBoxes++;
            }

        }

        System.out.println(numEmptyBoxes);

    }

}
0