結果

問題 No.5 数字のブロック
ユーザー mt09spmt09sp
提出日時 2023-04-25 18:03:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 202 ms / 5,000 ms
コード長 1,643 bytes
コンパイル時間 2,474 ms
コンパイル使用メモリ 74,508 KB
実行使用メモリ 43,636 KB
最終ジャッジ日時 2024-04-26 22:25:22
合計ジャッジ時間 8,716 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
39,796 KB
testcase_01 AC 115 ms
40,260 KB
testcase_02 AC 109 ms
40,092 KB
testcase_03 AC 180 ms
42,116 KB
testcase_04 AC 167 ms
41,752 KB
testcase_05 AC 198 ms
43,068 KB
testcase_06 AC 183 ms
42,328 KB
testcase_07 AC 181 ms
41,900 KB
testcase_08 AC 183 ms
42,572 KB
testcase_09 AC 164 ms
41,416 KB
testcase_10 AC 197 ms
43,528 KB
testcase_11 AC 176 ms
41,860 KB
testcase_12 AC 188 ms
42,344 KB
testcase_13 AC 191 ms
43,048 KB
testcase_14 AC 125 ms
41,280 KB
testcase_15 AC 129 ms
41,484 KB
testcase_16 AC 202 ms
43,240 KB
testcase_17 AC 202 ms
43,348 KB
testcase_18 AC 192 ms
43,636 KB
testcase_19 AC 201 ms
43,432 KB
testcase_20 AC 120 ms
41,136 KB
testcase_21 AC 127 ms
41,324 KB
testcase_22 AC 122 ms
41,072 KB
testcase_23 AC 122 ms
41,096 KB
testcase_24 AC 137 ms
41,492 KB
testcase_25 AC 134 ms
40,352 KB
testcase_26 AC 123 ms
41,544 KB
testcase_27 AC 111 ms
40,024 KB
testcase_28 AC 124 ms
41,100 KB
testcase_29 AC 171 ms
42,256 KB
testcase_30 AC 151 ms
40,912 KB
testcase_31 AC 109 ms
39,920 KB
testcase_32 AC 121 ms
41,184 KB
testcase_33 AC 122 ms
41,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) {
        // System.out.println("Hello World");
        // 入力を受け取る
        Scanner scan = new Scanner(System.in);
        String strL = scan.nextLine();
        String strN = scan.nextLine();
        String strW = scan.nextLine();
        scan.close();
        // 値を受け取る
        int l = Integer.parseInt(strL);
        int n = Integer.parseInt(strN);
        String[] arrW = strW.split(" ");
        int[] w = new int[arrW.length];
        for(int i = 0; i < arrW.length; i++) {
            w[i] = Integer.parseInt(arrW[i]);
        }
        // System.out.println(l);
        // System.out.println(n);
        // for(int i = 0; i < w.length; i++) {
        //     System.out.println(w[i]);
        // }
        
        
        // 計算
            //必要な変数
                // L’
                int lBox = 0;
                // count
                int count = 0;
            Arrays.sort(w);
            // for(int i = 0; i < w.length; i++) {
            // System.out.println(w[i]);
            // }
            // ループ開始
            for (int i = 0; i < w.length; i++) {
            // ソートしたW’を小さい順にL’に足していく
                lBox += w[i];
            // L<L’になったときループ終了
                if(l < lBox) {
                    break;
                }
            // countに1を足す
                count ++;
            }
        // 出力
            // countを出力
            System.out.println(count);
    }
}
0