結果

問題 No.5 数字のブロック
ユーザー mt09spmt09sp
提出日時 2023-04-25 18:29:36
言語 Java21
(openjdk 21)
結果
AC  
実行時間 218 ms / 5,000 ms
コード長 1,234 bytes
コンパイル時間 3,166 ms
コンパイル使用メモリ 75,812 KB
実行使用メモリ 43,344 KB
最終ジャッジ日時 2024-04-26 22:47:03
合計ジャッジ時間 8,982 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
40,284 KB
testcase_01 AC 124 ms
41,160 KB
testcase_02 AC 117 ms
40,316 KB
testcase_03 AC 191 ms
42,488 KB
testcase_04 AC 176 ms
41,672 KB
testcase_05 AC 203 ms
43,204 KB
testcase_06 AC 183 ms
41,996 KB
testcase_07 AC 182 ms
42,392 KB
testcase_08 AC 194 ms
42,484 KB
testcase_09 AC 173 ms
41,660 KB
testcase_10 AC 208 ms
42,992 KB
testcase_11 AC 177 ms
41,816 KB
testcase_12 AC 198 ms
42,668 KB
testcase_13 AC 205 ms
43,180 KB
testcase_14 AC 134 ms
41,436 KB
testcase_15 AC 133 ms
41,176 KB
testcase_16 AC 203 ms
43,344 KB
testcase_17 AC 218 ms
43,200 KB
testcase_18 AC 206 ms
43,192 KB
testcase_19 AC 212 ms
43,200 KB
testcase_20 AC 131 ms
41,460 KB
testcase_21 AC 128 ms
41,448 KB
testcase_22 AC 131 ms
41,316 KB
testcase_23 AC 129 ms
41,308 KB
testcase_24 AC 137 ms
41,460 KB
testcase_25 AC 142 ms
41,696 KB
testcase_26 AC 125 ms
41,120 KB
testcase_27 AC 129 ms
41,068 KB
testcase_28 AC 115 ms
40,456 KB
testcase_29 AC 169 ms
42,120 KB
testcase_30 AC 156 ms
41,260 KB
testcase_31 AC 130 ms
40,920 KB
testcase_32 AC 126 ms
41,236 KB
testcase_33 AC 126 ms
41,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) {
        // 入力を受け取る
        Scanner scan = new Scanner(System.in);
        String strL = scan.nextLine();
        String strN = scan.nextLine();
        String strW = scan.nextLine();
        scan.close();
        // 値を受け取る
        int boxLength = Integer.parseInt(strL);
        int blockNum = Integer.parseInt(strN);
        String[] arrW = strW.split(" ");
        int[] blockWidths = new int[arrW.length];
        for(int i = 0; i < arrW.length; i++) {
            blockWidths[i] = Integer.parseInt(arrW[i]);
        }
        // 計算
        int totalBlockWidths = 0;
        int count = 0;
        Arrays.sort(blockWidths);
        for (int i = 0; i < blockWidths.length; i++) {
        // ブロックを小さい順に箱へ足していく
            totalBlockWidths += blockWidths[i];
        // 箱にブロックが入らなくなったときループ終了
            if(boxLength < totalBlockWidths) {
                break;
            }
            count ++;
        }
        // 箱に入る最大のブロック個数を出力
        System.out.println(count);
    }
}
0