結果

問題 No.5 数字のブロック
ユーザー Daigo HIROOKA
提出日時 2018-05-11 22:42:48
言語 Java
(openjdk 23)
結果
RE  
実行時間 -
コード長 729 bytes
コンパイル時間 3,821 ms
コンパイル使用メモリ 77,684 KB
実行使用メモリ 59,520 KB
最終ジャッジ日時 2024-06-28 08:50:33
合計ジャッジ時間 11,737 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10 RE * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.Arrays;

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

        int L = sc.nextInt();
        int N = sc.nextInt();

        int[] W = new int[N];
        for(int i = 0; i < N; i++){
            W[i] = sc.nextInt();
        }
        Arrays.sort(W);
        int blocks_width = 0;
        for(int i = 0; i < N; i++){
            if(blocks_width + W[i] > L){
                System.out.println(i);
                System.exit(1);
            }else{
                blocks_width += W[i];
            }
        }
        System.out.println(W.length);
    }
}
0