結果

問題 No.5 数字のブロック
ユーザー IceEijiIceEiji
提出日時 2019-03-21 15:19:22
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 862 bytes
コンパイル時間 2,353 ms
コンパイル使用メモリ 74,480 KB
実行使用メモリ 62,068 KB
最終ジャッジ日時 2023-10-19 05:21:11
合計ジャッジ時間 10,540 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 136 ms
57,680 KB
testcase_01 AC 135 ms
57,572 KB
testcase_02 WA -
testcase_03 AC 252 ms
61,212 KB
testcase_04 AC 244 ms
60,868 KB
testcase_05 AC 260 ms
61,504 KB
testcase_06 AC 238 ms
61,400 KB
testcase_07 AC 234 ms
60,816 KB
testcase_08 AC 247 ms
61,116 KB
testcase_09 AC 210 ms
60,256 KB
testcase_10 AC 263 ms
61,688 KB
testcase_11 AC 230 ms
60,728 KB
testcase_12 AC 250 ms
61,676 KB
testcase_13 AC 264 ms
61,688 KB
testcase_14 AC 149 ms
57,704 KB
testcase_15 AC 171 ms
57,848 KB
testcase_16 AC 264 ms
59,852 KB
testcase_17 AC 279 ms
62,068 KB
testcase_18 AC 265 ms
61,772 KB
testcase_19 AC 282 ms
61,860 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 139 ms
57,372 KB
testcase_24 AC 159 ms
57,908 KB
testcase_25 AC 187 ms
57,888 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 233 ms
58,488 KB
testcase_30 AC 214 ms
59,896 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;


// 幅Lの箱の中に、高さ1で幅は𝑊𝑖のブロックが最大何個はいるのかを求めるプログラム。
class NumBlocks
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int l = sc.nextInt();
        int n = sc.nextInt();
        int[] intWi = new int[n];
        for (int i = 0; i < n; i++) {
            intWi[i] = sc.nextInt();
        }
        
        // ブロック(intWi)を幅が小さい順に並べる
        Arrays.sort(intWi);
        
        // 小さい順に箱に詰めていき、幅Lをギリギリこえない個数を求める
        int temp = 0;
        for (int i = 0; i < n; i++) {
            temp += intWi[i];
            if (l < temp) {
                System.out.println(i);
                return;
            }
        }
    }
}

0