結果
| 問題 | No.156 キャンディー・ボックス |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-12-02 21:04:20 |
| 言語 | Java (openjdk 25.0.2) |
| 結果 |
AC
|
| 実行時間 | 41 ms / 2,000 ms |
| + 448µs | |
| コード長 | 1,318 bytes |
| 記録 | |
| コンパイル時間 | 2,250 ms |
| コンパイル使用メモリ | 89,848 KB |
| 実行使用メモリ | 41,216 KB |
| 最終ジャッジ日時 | 2026-07-17 06:12:32 |
| 合計ジャッジ時間 | 5,397 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
ソースコード
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();
}
}