結果

問題 No.5 数字のブロック
ユーザー abcabc
提出日時 2016-10-16 14:02:18
言語 Java21
(openjdk 21)
結果
AC  
実行時間 255 ms / 5,000 ms
コード長 774 bytes
コンパイル時間 1,839 ms
コンパイル使用メモリ 74,576 KB
実行使用メモリ 47,756 KB
最終ジャッジ日時 2024-04-29 08:16:25
合計ジャッジ時間 8,556 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
41,372 KB
testcase_01 AC 107 ms
41,448 KB
testcase_02 AC 106 ms
41,212 KB
testcase_03 AC 206 ms
47,016 KB
testcase_04 AC 199 ms
45,732 KB
testcase_05 AC 229 ms
47,024 KB
testcase_06 AC 206 ms
46,400 KB
testcase_07 AC 197 ms
45,652 KB
testcase_08 AC 210 ms
47,092 KB
testcase_09 AC 185 ms
44,008 KB
testcase_10 AC 229 ms
46,908 KB
testcase_11 AC 196 ms
46,084 KB
testcase_12 AC 210 ms
46,584 KB
testcase_13 AC 226 ms
47,128 KB
testcase_14 AC 128 ms
41,320 KB
testcase_15 AC 159 ms
41,924 KB
testcase_16 AC 225 ms
46,852 KB
testcase_17 AC 234 ms
47,184 KB
testcase_18 AC 233 ms
47,756 KB
testcase_19 AC 255 ms
47,732 KB
testcase_20 AC 104 ms
41,372 KB
testcase_21 AC 119 ms
41,500 KB
testcase_22 AC 115 ms
41,552 KB
testcase_23 AC 116 ms
41,396 KB
testcase_24 AC 149 ms
41,540 KB
testcase_25 AC 160 ms
41,996 KB
testcase_26 AC 113 ms
41,068 KB
testcase_27 AC 112 ms
41,084 KB
testcase_28 AC 114 ms
41,208 KB
testcase_29 AC 196 ms
45,436 KB
testcase_30 AC 183 ms
43,764 KB
testcase_31 AC 117 ms
41,368 KB
testcase_32 AC 118 ms
41,128 KB
testcase_33 AC 123 ms
41,548 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