結果

問題 No.5 数字のブロック
ユーザー Ryugo Abe
提出日時 2016-12-15 14:42:23
言語 Java
(openjdk 23)
結果
AC  
実行時間 269 ms / 5,000 ms
コード長 790 bytes
コンパイル時間 2,238 ms
コンパイル使用メモリ 76,388 KB
実行使用メモリ 48,064 KB
最終ジャッジ日時 2024-11-18 10:48:37
合計ジャッジ時間 9,024 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int boxWidth = sc.nextInt();
        int numBlock = sc.nextInt();

        List<Integer> blockWidthList = new ArrayList<Integer>();
        for (int i = 0; i < numBlock; i++) {
            blockWidthList.add(sc.nextInt());
        }

        Collections.sort(blockWidthList);
        int count = 0;
        int filledWidth = 0;
        for (Integer width : blockWidthList) {
            filledWidth += width;
            if (filledWidth > boxWidth) {
                break;
            }
            count++;
        }

        System.out.println(count);
    }
}
0