結果

問題 No.5 数字のブロック
ユーザー tsunabittsunabit
提出日時 2018-04-15 11:44:13
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,826 bytes
コンパイル時間 3,303 ms
コンパイル使用メモリ 73,324 KB
実行使用メモリ 60,984 KB
最終ジャッジ日時 2023-09-09 05:40:21
合計ジャッジ時間 11,310 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
56,280 KB
testcase_01 AC 122 ms
56,120 KB
testcase_02 RE -
testcase_03 AC 244 ms
59,224 KB
testcase_04 AC 225 ms
59,528 KB
testcase_05 AC 258 ms
60,096 KB
testcase_06 AC 235 ms
59,292 KB
testcase_07 AC 213 ms
59,456 KB
testcase_08 AC 235 ms
59,240 KB
testcase_09 AC 195 ms
58,468 KB
testcase_10 AC 258 ms
60,384 KB
testcase_11 AC 215 ms
59,344 KB
testcase_12 AC 242 ms
59,720 KB
testcase_13 AC 253 ms
60,020 KB
testcase_14 AC 135 ms
55,980 KB
testcase_15 AC 146 ms
55,956 KB
testcase_16 AC 255 ms
60,324 KB
testcase_17 AC 271 ms
60,984 KB
testcase_18 AC 270 ms
60,456 KB
testcase_19 AC 278 ms
60,100 KB
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 122 ms
55,672 KB
testcase_24 AC 161 ms
55,512 KB
testcase_25 AC 183 ms
56,092 KB
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 AC 220 ms
59,192 KB
testcase_30 AC 196 ms
58,884 KB
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

// 問題文
// Ellenは数字のブロックで遊ぼうとしている。
// 数字が書かれているブロックはそれぞれ高さ1で幅はWi である。
// (同じ幅のブロックが複数存在することがある。)
// それらのブロックを高さ1,幅Lの箱の中に入れる。 
// Ellenは大きな箱にどれだけブロックがたくさん入るか気になったが。
// 組み合わせがたくさんあって大変なことに気づいて、すぐに夜になってしまいそうである。
// あなたは、代わりに大きな箱に最大何個のブロックが入るかを求めてください。
// ***
// 入力
// L
// N
// W1W2W3…WN
// 1行目は、大きな箱の幅を表すL(1≤L≤10000)が与えられます。
// 2行目は、ブロックの数を表すN(1≤N≤10000)
// 3行目は、各ブロックの幅を表すWi(1≤Wi≤L)が半角スペース区切りで与えられます。
// ***
// 出力
// 求めた数値を返してください。末尾に改行を付けてください。

public class No5 {
    public static void main(String[] args) {
        // 標準入力から読み込む際に、Scannerオブジェクトを使う。
        Scanner sc = new Scanner(System.in);
        int L = sc.nextInt(); // 箱の幅
        int N = sc.nextInt(); // ブロックの数

        ArrayList<Integer> al = new ArrayList<Integer>();
        for(int i = 0; i < N; i++) {
            al.add(sc.nextInt());
        }
        // 並び替え
        Collections.sort(al);
        int total = 0;
        int count = 0;
        while((total + al.get(count)) <= L) {
            total += al.get(count);
            count++;
        }
        System.out.println(count);
    }
}
0