結果

問題 No.5 数字のブロック
ユーザー トミートミー
提出日時 2024-03-31 19:28:21
言語 Java21
(openjdk 21)
結果
AC  
実行時間 274 ms / 5,000 ms
コード長 572 bytes
コンパイル時間 2,614 ms
コンパイル使用メモリ 78,948 KB
実行使用メモリ 63,064 KB
最終ジャッジ日時 2024-03-31 19:28:32
合計ジャッジ時間 10,497 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
57,960 KB
testcase_01 AC 134 ms
57,960 KB
testcase_02 AC 134 ms
57,944 KB
testcase_03 AC 244 ms
61,624 KB
testcase_04 AC 228 ms
61,044 KB
testcase_05 AC 259 ms
62,228 KB
testcase_06 AC 227 ms
62,084 KB
testcase_07 AC 221 ms
61,244 KB
testcase_08 AC 241 ms
61,340 KB
testcase_09 AC 212 ms
60,404 KB
testcase_10 AC 262 ms
61,804 KB
testcase_11 AC 235 ms
61,500 KB
testcase_12 AC 253 ms
62,204 KB
testcase_13 AC 259 ms
62,020 KB
testcase_14 AC 150 ms
57,912 KB
testcase_15 AC 155 ms
56,132 KB
testcase_16 AC 260 ms
62,088 KB
testcase_17 AC 268 ms
62,540 KB
testcase_18 AC 273 ms
63,064 KB
testcase_19 AC 274 ms
62,776 KB
testcase_20 AC 133 ms
57,960 KB
testcase_21 AC 133 ms
58,072 KB
testcase_22 AC 132 ms
57,952 KB
testcase_23 AC 135 ms
58,080 KB
testcase_24 AC 158 ms
58,200 KB
testcase_25 AC 188 ms
58,604 KB
testcase_26 AC 135 ms
57,840 KB
testcase_27 AC 132 ms
57,976 KB
testcase_28 AC 132 ms
57,964 KB
testcase_29 AC 225 ms
61,344 KB
testcase_30 AC 216 ms
60,444 KB
testcase_31 AC 135 ms
58,100 KB
testcase_32 AC 133 ms
57,972 KB
testcase_33 AC 131 ms
57,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    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();
        }
        sc.close();
        Arrays.sort(w);
        int cnt = 0;
        int sum = 0;
        for (cnt = 0; cnt < n && sum <= l; cnt++) {
            sum += w[cnt];
        }
        if (sum > l) {
            cnt--;
        }
        System.out.println(cnt);

    }
}
0