結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
41,120 KB
testcase_01 AC 120 ms
39,968 KB
testcase_02 AC 130 ms
41,200 KB
testcase_03 AC 253 ms
46,884 KB
testcase_04 AC 221 ms
45,496 KB
testcase_05 AC 258 ms
46,824 KB
testcase_06 AC 237 ms
46,184 KB
testcase_07 AC 228 ms
45,340 KB
testcase_08 AC 252 ms
46,784 KB
testcase_09 AC 211 ms
43,080 KB
testcase_10 AC 265 ms
46,796 KB
testcase_11 AC 233 ms
46,140 KB
testcase_12 AC 251 ms
46,332 KB
testcase_13 AC 267 ms
46,220 KB
testcase_14 AC 146 ms
41,324 KB
testcase_15 AC 160 ms
41,648 KB
testcase_16 AC 270 ms
46,544 KB
testcase_17 AC 272 ms
47,212 KB
testcase_18 AC 276 ms
47,540 KB
testcase_19 AC 282 ms
47,576 KB
testcase_20 WA -
testcase_21 AC 133 ms
41,384 KB
testcase_22 AC 131 ms
41,144 KB
testcase_23 AC 131 ms
41,216 KB
testcase_24 AC 168 ms
41,864 KB
testcase_25 AC 184 ms
41,872 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 223 ms
45,292 KB
testcase_30 AC 214 ms
43,500 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;
            } else if (l == temp) {
                System.out.println(i+1);
                return;
            }
        }
    }
}

0