結果

問題 No.5 数字のブロック
ユーザー tokustokus
提出日時 2021-11-15 23:15:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 120 ms / 5,000 ms
コード長 1,100 bytes
コンパイル時間 3,132 ms
コンパイル使用メモリ 77,872 KB
実行使用メモリ 48,820 KB
最終ジャッジ日時 2023-08-21 18:20:22
合計ジャッジ時間 7,106 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
34,740 KB
testcase_01 AC 54 ms
35,252 KB
testcase_02 AC 53 ms
35,028 KB
testcase_03 AC 93 ms
36,944 KB
testcase_04 AC 75 ms
36,104 KB
testcase_05 AC 99 ms
37,276 KB
testcase_06 AC 87 ms
48,820 KB
testcase_07 AC 76 ms
36,104 KB
testcase_08 AC 92 ms
36,656 KB
testcase_09 AC 69 ms
35,876 KB
testcase_10 AC 102 ms
37,808 KB
testcase_11 AC 76 ms
36,292 KB
testcase_12 AC 96 ms
36,988 KB
testcase_13 AC 99 ms
37,240 KB
testcase_14 AC 52 ms
35,088 KB
testcase_15 AC 57 ms
35,060 KB
testcase_16 AC 102 ms
37,892 KB
testcase_17 AC 116 ms
38,232 KB
testcase_18 AC 115 ms
38,080 KB
testcase_19 AC 120 ms
38,960 KB
testcase_20 AC 53 ms
34,856 KB
testcase_21 AC 53 ms
35,204 KB
testcase_22 AC 54 ms
34,988 KB
testcase_23 AC 58 ms
34,896 KB
testcase_24 AC 58 ms
35,028 KB
testcase_25 AC 65 ms
35,608 KB
testcase_26 AC 58 ms
34,988 KB
testcase_27 AC 53 ms
34,904 KB
testcase_28 AC 54 ms
35,000 KB
testcase_29 AC 76 ms
36,504 KB
testcase_30 AC 69 ms
36,288 KB
testcase_31 AC 52 ms
34,976 KB
testcase_32 AC 54 ms
34,808 KB
testcase_33 AC 53 ms
34,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.stream.Stream;

class Main {
    public static void main(String[] args) {
        no5();
    }

    // No.5 数字のブロック
    private static void no5() {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        // 箱の幅
        String l;
        // ブロックの数
        String n;
        // 各ブロックの幅
        String block;

        try {
            l = reader.readLine();
            n = reader.readLine();
            block = reader.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        int[] numbers = Stream.of(block.split(" ")).mapToInt(Integer::parseInt).sorted().toArray();

        int width = Integer.parseInt(l);

        int max = 0;

        for (int i : numbers) {
            if (i <= width) {
                width -= i;
                max++;
            } else {
                break;
            };
        }
        System.out.println(max);
    }
}
0