結果

問題 No.5 数字のブロック
ユーザー abcabc
提出日時 2016-10-16 14:02:18
言語 Java21
(openjdk 21)
結果
AC  
実行時間 264 ms / 5,000 ms
コード長 774 bytes
コンパイル時間 2,133 ms
コンパイル使用メモリ 71,648 KB
実行使用メモリ 61,804 KB
最終ジャッジ日時 2023-08-11 16:26:15
合計ジャッジ時間 10,135 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,732 KB
testcase_01 AC 131 ms
55,876 KB
testcase_02 AC 129 ms
55,432 KB
testcase_03 AC 237 ms
59,212 KB
testcase_04 AC 211 ms
59,132 KB
testcase_05 AC 255 ms
60,752 KB
testcase_06 AC 228 ms
59,916 KB
testcase_07 AC 212 ms
58,572 KB
testcase_08 AC 237 ms
57,240 KB
testcase_09 AC 200 ms
58,484 KB
testcase_10 AC 252 ms
59,844 KB
testcase_11 AC 227 ms
59,608 KB
testcase_12 AC 235 ms
59,100 KB
testcase_13 AC 258 ms
61,804 KB
testcase_14 AC 143 ms
55,564 KB
testcase_15 AC 158 ms
55,864 KB
testcase_16 AC 250 ms
59,964 KB
testcase_17 AC 264 ms
60,828 KB
testcase_18 AC 262 ms
60,244 KB
testcase_19 AC 262 ms
60,452 KB
testcase_20 AC 130 ms
55,588 KB
testcase_21 AC 129 ms
55,680 KB
testcase_22 AC 130 ms
55,844 KB
testcase_23 AC 129 ms
56,032 KB
testcase_24 AC 157 ms
56,116 KB
testcase_25 AC 190 ms
56,136 KB
testcase_26 AC 129 ms
55,908 KB
testcase_27 AC 130 ms
55,552 KB
testcase_28 AC 130 ms
55,676 KB
testcase_29 AC 211 ms
59,316 KB
testcase_30 AC 209 ms
58,404 KB
testcase_31 AC 128 ms
55,568 KB
testcase_32 AC 130 ms
55,968 KB
testcase_33 AC 130 ms
55,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

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

        int[] widthBlocks = new int[numBlock];

        for (int i = 0; i < numBlock; i++) {
            widthBlocks[i] = sc.nextInt();
        }

        Arrays.sort(widthBlocks);

        int blockCount = 0;
        int widthBlockTotal = 0;

        for (int i = 0; i < numBlock; i++) {

            widthBlockTotal += widthBlocks[i];

            if (widthBlockTotal <= widthBox) {
                blockCount++;
            } else {
                break;
            }

        }

        System.out.println(blockCount);

    }

}
0