結果

問題 No.5 数字のブロック
ユーザー Flere0114Flere0114
提出日時 2016-02-24 13:11:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 250 ms / 5,000 ms
コード長 599 bytes
コンパイル時間 3,191 ms
コンパイル使用メモリ 73,212 KB
実行使用メモリ 62,376 KB
最終ジャッジ日時 2023-08-11 14:44:21
合計ジャッジ時間 10,524 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
55,544 KB
testcase_01 AC 123 ms
56,064 KB
testcase_02 AC 121 ms
55,972 KB
testcase_03 AC 216 ms
59,896 KB
testcase_04 AC 205 ms
59,224 KB
testcase_05 AC 235 ms
60,060 KB
testcase_06 AC 215 ms
59,916 KB
testcase_07 AC 208 ms
59,500 KB
testcase_08 AC 213 ms
59,856 KB
testcase_09 AC 190 ms
58,868 KB
testcase_10 AC 234 ms
60,032 KB
testcase_11 AC 214 ms
59,656 KB
testcase_12 AC 214 ms
59,864 KB
testcase_13 AC 232 ms
59,844 KB
testcase_14 AC 131 ms
56,272 KB
testcase_15 AC 142 ms
56,368 KB
testcase_16 AC 234 ms
59,748 KB
testcase_17 AC 250 ms
62,192 KB
testcase_18 AC 247 ms
60,704 KB
testcase_19 AC 249 ms
62,376 KB
testcase_20 AC 120 ms
55,828 KB
testcase_21 AC 121 ms
56,220 KB
testcase_22 AC 119 ms
55,872 KB
testcase_23 AC 120 ms
54,328 KB
testcase_24 AC 154 ms
56,312 KB
testcase_25 AC 173 ms
56,044 KB
testcase_26 AC 119 ms
56,324 KB
testcase_27 AC 120 ms
56,572 KB
testcase_28 AC 118 ms
56,100 KB
testcase_29 AC 204 ms
59,028 KB
testcase_30 AC 188 ms
58,436 KB
testcase_31 AC 115 ms
56,136 KB
testcase_32 AC 119 ms
56,360 KB
testcase_33 AC 118 ms
56,364 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, n, sum = 0, ans = 0;
        l = sc.nextInt();
        n = sc.nextInt();
        int[] w = new int[n];
        for (int i = 0; i < n; i++) {
            w[i] = sc.nextInt();
        }
        Arrays.sort(w);

        for (int i = 0; i < n; i++) {
            sum += w[i];
            if(sum > l){
                System.out.println(i);
                return;
            }
        }
        System.out.println(n);
    }
}
0