結果

問題 No.156 キャンディー・ボックス
ユーザー dazydazy
提出日時 2016-09-23 14:04:57
言語 Java21
(openjdk 21)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 808 bytes
コンパイル時間 4,830 ms
コンパイル使用メモリ 71,892 KB
実行使用メモリ 56,040 KB
最終ジャッジ日時 2023-09-19 03:14:45
合計ジャッジ時間 10,874 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
55,428 KB
testcase_01 AC 133 ms
55,424 KB
testcase_02 AC 131 ms
55,320 KB
testcase_03 AC 130 ms
56,040 KB
testcase_04 AC 130 ms
55,360 KB
testcase_05 AC 131 ms
55,364 KB
testcase_06 AC 127 ms
55,600 KB
testcase_07 AC 130 ms
55,484 KB
testcase_08 AC 131 ms
55,612 KB
testcase_09 AC 129 ms
55,224 KB
testcase_10 AC 129 ms
55,588 KB
testcase_11 AC 130 ms
55,608 KB
testcase_12 AC 129 ms
55,420 KB
testcase_13 AC 131 ms
55,652 KB
testcase_14 AC 131 ms
55,372 KB
testcase_15 AC 131 ms
55,260 KB
testcase_16 AC 128 ms
55,220 KB
testcase_17 AC 130 ms
55,560 KB
testcase_18 AC 127 ms
55,544 KB
testcase_19 AC 126 ms
55,652 KB
testcase_20 AC 127 ms
55,424 KB
testcase_21 AC 130 ms
55,368 KB
testcase_22 AC 127 ms
55,356 KB
testcase_23 AC 129 ms
55,224 KB
testcase_24 AC 127 ms
55,612 KB
testcase_25 AC 130 ms
55,648 KB
testcase_26 AC 129 ms
55,544 KB
testcase_27 AC 131 ms
55,532 KB
testcase_28 AC 131 ms
55,612 KB
testcase_29 AC 132 ms
55,612 KB
testcase_30 AC 129 ms
55,800 KB
testcase_31 AC 132 ms
55,656 KB
testcase_32 AC 133 ms
55,508 KB
testcase_33 AC 136 ms
55,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Run {
    public static void main (String arg[]) {
        Scanner scan = new Scanner(System.in);
        int N,M;
        N = scan.nextInt();
        M = scan.nextInt();
        int[] C = new int[N];
        int i, tmp, min, ans = 0;
        for (i = 0; i < N; i++) C[i] = scan.nextInt();
        for (int j = 0; j < N; j++) {
            min = C[j];
            for (i = N - 1; i > j; i--) {
                if (min > C[i]) {
                    tmp = min;
                    min = C[i];
                    C[i] = tmp;
                }
            }
            if (M >= min) {
                M -= min;
                ans++;
                if (M==0) break;
            } else {
                break;
            }
        }
        System.out.println(ans);
    }
}
0