結果

問題 No.5 数字のブロック
ユーザー l1267976l1267976
提出日時 2017-03-07 13:38:52
言語 Java19
(openjdk 21)
結果
AC  
実行時間 269 ms / 5,000 ms
コード長 648 bytes
コンパイル時間 3,589 ms
コンパイル使用メモリ 72,196 KB
実行使用メモリ 62,292 KB
最終ジャッジ日時 2023-08-11 17:08:48
合計ジャッジ時間 11,490 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
55,972 KB
testcase_01 AC 125 ms
53,760 KB
testcase_02 AC 124 ms
55,580 KB
testcase_03 AC 233 ms
59,720 KB
testcase_04 AC 219 ms
59,128 KB
testcase_05 AC 247 ms
60,584 KB
testcase_06 AC 227 ms
59,760 KB
testcase_07 AC 223 ms
57,008 KB
testcase_08 AC 234 ms
59,792 KB
testcase_09 AC 199 ms
59,320 KB
testcase_10 AC 247 ms
60,516 KB
testcase_11 AC 222 ms
59,124 KB
testcase_12 AC 237 ms
59,688 KB
testcase_13 AC 250 ms
59,832 KB
testcase_14 AC 139 ms
56,200 KB
testcase_15 AC 153 ms
55,792 KB
testcase_16 AC 245 ms
59,892 KB
testcase_17 AC 258 ms
60,852 KB
testcase_18 AC 256 ms
62,292 KB
testcase_19 AC 269 ms
60,532 KB
testcase_20 AC 127 ms
56,140 KB
testcase_21 AC 127 ms
55,876 KB
testcase_22 AC 129 ms
55,664 KB
testcase_23 AC 127 ms
56,160 KB
testcase_24 AC 154 ms
55,780 KB
testcase_25 AC 183 ms
56,132 KB
testcase_26 AC 126 ms
55,892 KB
testcase_27 AC 128 ms
55,724 KB
testcase_28 AC 127 ms
55,872 KB
testcase_29 AC 218 ms
58,900 KB
testcase_30 AC 205 ms
56,832 KB
testcase_31 AC 125 ms
55,740 KB
testcase_32 AC 126 ms
56,072 KB
testcase_33 AC 125 ms
55,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class No5 {

    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 sum = 0;
        int cnt = 0;

        for (int i = 0; i < n; i++) {
            sum += w[i];

            if (sum > l) {
                break;
            } else {
                cnt++;
            }
        }

        System.out.println(cnt);

        sc.close();
    }

}
0