結果

問題 No.5 数字のブロック
ユーザー Daigo HIROOKA
提出日時 2018-05-11 22:46:16
言語 Java
(openjdk 23)
結果
AC  
実行時間 260 ms / 5,000 ms
コード長 740 bytes
コンパイル時間 3,214 ms
コンパイル使用メモリ 76,456 KB
実行使用メモリ 47,840 KB
最終ジャッジ日時 2024-11-18 12:24:22
合計ジャッジ時間 10,306 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

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;
        int num_blocks = 0;
        for(int i = 0; i < N; i++){
            if(blocks_width + W[i] > L){
                break;
            }else{
                blocks_width += W[i];
                num_blocks++;
            }
        }
        System.out.println(num_blocks);
    }
}
0