結果

問題 No.5 数字のブロック
ユーザー yukiyuki
提出日時 2020-08-20 00:14:12
言語 Java21
(openjdk 21)
結果
AC  
実行時間 282 ms / 5,000 ms
コード長 684 bytes
コンパイル時間 2,074 ms
コンパイル使用メモリ 76,876 KB
実行使用メモリ 59,468 KB
最終ジャッジ日時 2024-04-20 14:46:36
合計ジャッジ時間 9,707 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
53,812 KB
testcase_01 AC 128 ms
54,060 KB
testcase_02 AC 129 ms
54,084 KB
testcase_03 AC 244 ms
58,604 KB
testcase_04 AC 225 ms
57,896 KB
testcase_05 AC 259 ms
58,804 KB
testcase_06 AC 238 ms
57,680 KB
testcase_07 AC 230 ms
57,680 KB
testcase_08 AC 241 ms
58,380 KB
testcase_09 AC 204 ms
56,540 KB
testcase_10 AC 263 ms
58,740 KB
testcase_11 AC 226 ms
57,916 KB
testcase_12 AC 246 ms
58,516 KB
testcase_13 AC 256 ms
58,752 KB
testcase_14 AC 146 ms
54,600 KB
testcase_15 AC 160 ms
54,696 KB
testcase_16 AC 265 ms
58,604 KB
testcase_17 AC 276 ms
58,952 KB
testcase_18 AC 276 ms
58,988 KB
testcase_19 AC 282 ms
59,468 KB
testcase_20 AC 126 ms
54,168 KB
testcase_21 AC 124 ms
54,408 KB
testcase_22 AC 126 ms
54,200 KB
testcase_23 AC 125 ms
54,144 KB
testcase_24 AC 156 ms
54,012 KB
testcase_25 AC 176 ms
54,092 KB
testcase_26 AC 127 ms
54,124 KB
testcase_27 AC 113 ms
53,100 KB
testcase_28 AC 126 ms
54,244 KB
testcase_29 AC 225 ms
57,628 KB
testcase_30 AC 205 ms
56,856 KB
testcase_31 AC 126 ms
54,076 KB
testcase_32 AC 126 ms
54,168 KB
testcase_33 AC 124 ms
54,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        long box = in.nextLong();
        long N = in.nextLong();
        List<Long> list = new ArrayList<>();

        for(long i=0; i<N; i++){
            long block = in.nextLong();
            list.add(block);
        }
        // 5 7 10
        Collections.sort(list);

        long sum = 0;
        long count = 0;
        for(int i=0; i<N; i++){
            if( (sum + list.get(i)) <= box){
                sum += list.get(i);
                count++;
            }
        }
        System.out.println(count);
        
    }
}

0