結果

問題 No.5 数字のブロック
ユーザー yagi2yagi2
提出日時 2017-04-26 12:54:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 240 ms / 5,000 ms
コード長 790 bytes
コンパイル時間 2,601 ms
コンパイル使用メモリ 75,768 KB
実行使用メモリ 60,324 KB
最終ジャッジ日時 2023-08-11 17:16:53
合計ジャッジ時間 9,404 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,892 KB
testcase_01 AC 121 ms
57,484 KB
testcase_02 AC 121 ms
55,436 KB
testcase_03 AC 216 ms
59,500 KB
testcase_04 AC 201 ms
59,256 KB
testcase_05 AC 228 ms
59,880 KB
testcase_06 AC 210 ms
59,204 KB
testcase_07 AC 195 ms
58,644 KB
testcase_08 AC 212 ms
59,388 KB
testcase_09 AC 181 ms
56,104 KB
testcase_10 AC 233 ms
60,324 KB
testcase_11 AC 199 ms
58,776 KB
testcase_12 AC 213 ms
59,176 KB
testcase_13 AC 225 ms
59,964 KB
testcase_14 AC 132 ms
55,668 KB
testcase_15 AC 137 ms
55,672 KB
testcase_16 AC 224 ms
59,696 KB
testcase_17 AC 240 ms
60,152 KB
testcase_18 AC 239 ms
60,160 KB
testcase_19 AC 240 ms
59,748 KB
testcase_20 AC 121 ms
55,664 KB
testcase_21 AC 122 ms
55,628 KB
testcase_22 AC 123 ms
55,556 KB
testcase_23 AC 122 ms
55,728 KB
testcase_24 AC 143 ms
55,836 KB
testcase_25 AC 171 ms
56,220 KB
testcase_26 AC 123 ms
55,648 KB
testcase_27 AC 121 ms
55,576 KB
testcase_28 AC 121 ms
55,624 KB
testcase_29 AC 195 ms
58,160 KB
testcase_30 AC 182 ms
56,408 KB
testcase_31 AC 121 ms
56,148 KB
testcase_32 AC 121 ms
55,564 KB
testcase_33 AC 123 ms
55,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder.No5;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

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

        int L = Integer.parseInt(sc.next());
        int N = Integer.parseInt(sc.next());

        List<Integer> blocks = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            blocks.add(Integer.parseInt(sc.next()));
        }
        Collections.sort(blocks);

        int ans = 0;
        for (int i = 0; i < N; i++) {
            if (L - blocks.get(i) >= 0) {
                ans++;
                L -= blocks.get(i);
            } else {
                break;
            }
        }

        System.out.println(ans);
    }
}
0