結果

問題 No.156 キャンディー・ボックス
ユーザー yagi2yagi2
提出日時 2017-04-24 17:12:14
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,138 ms / 2,000 ms
コード長 937 bytes
コンパイル時間 3,006 ms
コンパイル使用メモリ 84,476 KB
実行使用メモリ 62,284 KB
最終ジャッジ日時 2023-09-19 03:22:40
合計ジャッジ時間 13,713 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 183 ms
55,908 KB
testcase_01 AC 126 ms
55,644 KB
testcase_02 AC 126 ms
55,412 KB
testcase_03 AC 126 ms
55,760 KB
testcase_04 AC 126 ms
56,136 KB
testcase_05 AC 272 ms
59,620 KB
testcase_06 AC 374 ms
61,296 KB
testcase_07 AC 348 ms
61,320 KB
testcase_08 AC 311 ms
59,624 KB
testcase_09 AC 278 ms
59,096 KB
testcase_10 AC 331 ms
59,872 KB
testcase_11 AC 272 ms
58,696 KB
testcase_12 AC 377 ms
60,316 KB
testcase_13 AC 316 ms
59,468 KB
testcase_14 AC 275 ms
59,416 KB
testcase_15 AC 331 ms
59,740 KB
testcase_16 AC 272 ms
58,944 KB
testcase_17 AC 307 ms
58,888 KB
testcase_18 AC 227 ms
58,652 KB
testcase_19 AC 239 ms
58,244 KB
testcase_20 AC 149 ms
55,788 KB
testcase_21 AC 184 ms
56,272 KB
testcase_22 AC 221 ms
58,488 KB
testcase_23 AC 196 ms
55,676 KB
testcase_24 AC 124 ms
55,744 KB
testcase_25 AC 127 ms
55,660 KB
testcase_26 AC 123 ms
55,352 KB
testcase_27 AC 126 ms
55,852 KB
testcase_28 AC 125 ms
55,756 KB
testcase_29 AC 126 ms
56,020 KB
testcase_30 AC 396 ms
57,684 KB
testcase_31 AC 306 ms
59,004 KB
testcase_32 AC 1,138 ms
60,068 KB
testcase_33 AC 1,116 ms
62,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = Integer.parseInt(sc.next());
        int M = Integer.parseInt(sc.next());

        List<Integer> candies = new ArrayList<>();

        for (int i = 0; i < N; i++) {
            candies.add(Integer.parseInt(sc.next()));
        }
        Collections.sort(candies);

        int index = 0;
        for (int i = 0; i < M; i++) {
            if (candies.get(index) == 0) index++;
            int tmp = candies.get(index);
            candies.remove(index);
            candies.add(tmp - 1);
            Collections.sort(candies);
        }

        final int[] cnt = {0};
        candies.forEach(integer -> {
            if (integer == 0) cnt[0]++;
        });

        System.out.println(cnt[0]);
    }
}
0