結果

問題 No.156 キャンディー・ボックス
コンテスト
ユーザー kitamoto0407
提出日時 2025-12-02 21:04:20
言語 Java
(openjdk 23)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 1,318 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,484 ms
コンパイル使用メモリ 83,528 KB
実行使用メモリ 45,384 KB
最終ジャッジ日時 2025-12-02 21:04:27
合計ジャッジ時間 6,757 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.io.*;
import java.util.*;
import java.util.stream.*;

// 処理
class Process {
    private int   M;
    private int[] C;

    Process(int M, int[] C) {
        this.M = M;
        this.C = C;
    }

    int getResult() {
        int[] sortedC = IntStream.of(C).sorted().toArray();
        
        int sum = 0;
        int emptyBoxCount = 0;
        for(int i = 0; i < sortedC.length; i++) {
            sum += sortedC[i];
            
            if(sum > M) {
                break;
            }

            emptyBoxCount++;
        }

        return emptyBoxCount;
    }
}

public class Main {
    public static void main(String[] args) throws IOException {
        var bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        var printWriter    = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

        // 入力
        int[] input = Stream.of(bufferedReader.readLine().trim().split("[ ]+")).mapToInt(Integer::parseInt).toArray();
        int N = input[0];
        int M = input[1];

        int[] C = Stream.of(bufferedReader.readLine().trim().split("[ ]+")).mapToInt(Integer::parseInt).toArray();

        // 出力
        printWriter.println((new Process(M, C)).getResult());

        bufferedReader.close();
        printWriter.close();
    }
}
0