結果

問題 No.156 キャンディー・ボックス
ユーザー mobius_bkstmobius_bkst
提出日時 2015-04-22 21:41:58
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,112 bytes
コンパイル時間 4,282 ms
コンパイル使用メモリ 75,200 KB
実行使用メモリ 51,264 KB
最終ジャッジ日時 2023-09-18 08:22:38
合計ジャッジ時間 5,973 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 42 ms
49,552 KB
testcase_03 AC 41 ms
49,364 KB
testcase_04 AC 42 ms
49,388 KB
testcase_05 AC 42 ms
49,168 KB
testcase_06 AC 42 ms
49,660 KB
testcase_07 AC 42 ms
49,424 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 42 ms
49,456 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 43 ms
47,560 KB
testcase_15 AC 43 ms
49,324 KB
testcase_16 AC 43 ms
47,972 KB
testcase_17 AC 43 ms
49,488 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 42 ms
47,544 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 42 ms
49,224 KB
testcase_27 AC 42 ms
49,504 KB
testcase_28 AC 42 ms
49,328 KB
testcase_29 AC 43 ms
49,380 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 43 ms
49,360 KB
testcase_33 AC 42 ms
49,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class No156 {


    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(
                    System.in));
            String[] nm = br.readLine().split(" ");
            int N = Integer.parseInt(nm[0]);
            int M = Integer.parseInt(nm[1]);

            String[] CStr = br.readLine().split(" ");
            int[] C = new int[N];
            for (int i = 0; i < N; i++) {
                C[i] = Integer.parseInt(CStr[1]);
            }

            System.out.println(solve(N, M, C));

        } catch (Exception e) {
            System.err.println("Error:" + e.getMessage());
        }
    }

    static int solve(int N, int M, int[] C){
        Arrays.sort(C);
        int emptyCount = 0;
        for (int i = 0; i < C.length; i++) {

            if (C[i] <= M) {
                M = M - C[i];
                emptyCount++;
            } else {
                break;
            }

        }
        return emptyCount;
    }

}
0