結果

問題 No.5 数字のブロック
ユーザー Daigo HIROOKADaigo HIROOKA
提出日時 2018-05-11 22:46:16
言語 Java21
(openjdk 21)
結果
AC  
実行時間 275 ms / 5,000 ms
コード長 740 bytes
コンパイル時間 3,637 ms
コンパイル使用メモリ 75,248 KB
実行使用メモリ 47,664 KB
最終ジャッジ日時 2024-04-29 09:50:03
合計ジャッジ時間 11,469 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
41,392 KB
testcase_01 AC 135 ms
41,808 KB
testcase_02 AC 130 ms
41,420 KB
testcase_03 AC 248 ms
46,820 KB
testcase_04 AC 220 ms
45,928 KB
testcase_05 AC 260 ms
46,704 KB
testcase_06 AC 235 ms
46,136 KB
testcase_07 AC 229 ms
45,848 KB
testcase_08 AC 247 ms
46,560 KB
testcase_09 AC 202 ms
43,504 KB
testcase_10 AC 263 ms
47,280 KB
testcase_11 AC 233 ms
45,944 KB
testcase_12 AC 253 ms
46,936 KB
testcase_13 AC 260 ms
47,304 KB
testcase_14 AC 147 ms
41,908 KB
testcase_15 AC 154 ms
41,592 KB
testcase_16 AC 262 ms
47,032 KB
testcase_17 AC 265 ms
47,664 KB
testcase_18 AC 275 ms
47,596 KB
testcase_19 AC 270 ms
47,568 KB
testcase_20 AC 134 ms
41,380 KB
testcase_21 AC 131 ms
41,680 KB
testcase_22 AC 135 ms
41,220 KB
testcase_23 AC 132 ms
41,344 KB
testcase_24 AC 156 ms
42,040 KB
testcase_25 AC 182 ms
41,876 KB
testcase_26 AC 133 ms
41,356 KB
testcase_27 AC 135 ms
41,260 KB
testcase_28 AC 131 ms
41,104 KB
testcase_29 AC 224 ms
45,800 KB
testcase_30 AC 206 ms
44,008 KB
testcase_31 AC 134 ms
41,404 KB
testcase_32 AC 132 ms
41,524 KB
testcase_33 AC 133 ms
41,476 KB
権限があれば一括ダウンロードができます

ソースコード

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