結果

問題 No.156 キャンディー・ボックス
ユーザー koukonkokoukonko
提出日時 2015-12-13 02:36:47
言語 Java21
(openjdk 21)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 848 bytes
コンパイル時間 2,204 ms
コンパイル使用メモリ 75,236 KB
実行使用メモリ 49,760 KB
最終ジャッジ日時 2023-09-19 03:02:56
合計ジャッジ時間 5,244 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,560 KB
testcase_01 AC 46 ms
48,976 KB
testcase_02 AC 45 ms
49,468 KB
testcase_03 AC 44 ms
49,476 KB
testcase_04 AC 45 ms
48,976 KB
testcase_05 AC 45 ms
49,232 KB
testcase_06 AC 48 ms
49,416 KB
testcase_07 AC 48 ms
49,184 KB
testcase_08 AC 45 ms
49,500 KB
testcase_09 AC 46 ms
49,184 KB
testcase_10 AC 44 ms
49,380 KB
testcase_11 AC 44 ms
49,192 KB
testcase_12 AC 46 ms
49,232 KB
testcase_13 AC 45 ms
49,328 KB
testcase_14 AC 45 ms
49,372 KB
testcase_15 AC 45 ms
49,180 KB
testcase_16 AC 45 ms
49,344 KB
testcase_17 AC 46 ms
49,760 KB
testcase_18 AC 45 ms
49,224 KB
testcase_19 AC 45 ms
49,340 KB
testcase_20 AC 46 ms
49,192 KB
testcase_21 AC 45 ms
49,400 KB
testcase_22 AC 46 ms
49,344 KB
testcase_23 AC 45 ms
47,352 KB
testcase_24 AC 45 ms
48,976 KB
testcase_25 AC 47 ms
49,340 KB
testcase_26 AC 45 ms
49,376 KB
testcase_27 AC 47 ms
49,468 KB
testcase_28 AC 47 ms
49,216 KB
testcase_29 AC 47 ms
49,596 KB
testcase_30 AC 45 ms
49,292 KB
testcase_31 AC 45 ms
49,480 KB
testcase_32 AC 44 ms
49,368 KB
testcase_33 AC 46 ms
49,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
	public static void main(String[] args) {
		BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
		try {
			String[] box = read.readLine().split(" ");
			int[] num = new int[2];
			for (int i = 0; i < 2; ++i) {
				num[i] = Integer.parseInt(box[i]);
			}

			box = read.readLine().split(" ");
			ArrayList<Integer> array = new ArrayList<>(num[0]);
			for (int i = 0; i < num[0]; ++i) {
				array.add(Integer.parseInt(box[i]));
			}
			array.sort(null);

			int ans = 0;
			for (int i = 0; i < num[0]; ++i) {
				if (num[1] - array.get(i) >= 0) {
					num[1] -= array.get(i);
					ans++;
				} else {
					break;
				}
			}

			System.out.println(ans);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
0