結果

問題 No.156 キャンディー・ボックス
ユーザー k_kadorak_kadora
提出日時 2015-05-27 03:37:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 393 bytes
コンパイル時間 4,859 ms
コンパイル使用メモリ 72,264 KB
実行使用メモリ 56,512 KB
最終ジャッジ日時 2023-09-18 19:36:41
合計ジャッジ時間 9,147 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,864 KB
testcase_01 AC 124 ms
56,160 KB
testcase_02 AC 123 ms
56,512 KB
testcase_03 AC 123 ms
55,872 KB
testcase_04 AC 122 ms
55,560 KB
testcase_05 AC 122 ms
55,632 KB
testcase_06 AC 125 ms
55,652 KB
testcase_07 AC 125 ms
55,992 KB
testcase_08 AC 124 ms
55,992 KB
testcase_09 AC 125 ms
55,852 KB
testcase_10 AC 124 ms
56,080 KB
testcase_11 AC 124 ms
55,560 KB
testcase_12 AC 121 ms
56,052 KB
testcase_13 AC 124 ms
56,072 KB
testcase_14 AC 122 ms
55,576 KB
testcase_15 AC 122 ms
55,904 KB
testcase_16 AC 122 ms
55,852 KB
testcase_17 AC 121 ms
55,884 KB
testcase_18 AC 124 ms
56,020 KB
testcase_19 AC 126 ms
55,848 KB
testcase_20 AC 124 ms
55,664 KB
testcase_21 AC 124 ms
53,964 KB
testcase_22 AC 124 ms
55,564 KB
testcase_23 AC 123 ms
56,112 KB
testcase_24 AC 124 ms
55,452 KB
testcase_25 AC 120 ms
55,440 KB
testcase_26 AC 121 ms
56,140 KB
testcase_27 AC 120 ms
55,872 KB
testcase_28 AC 120 ms
56,128 KB
testcase_29 AC 121 ms
55,720 KB
testcase_30 AC 123 ms
55,716 KB
testcase_31 AC 122 ms
55,864 KB
testcase_32 AC 122 ms
55,776 KB
testcase_33 AC 123 ms
55,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
public class Candy{
	public static void main(String[] arg){
		int n,m,res = 0;
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		m = sc.nextInt();
		int[] c = new int[n];
		for(int i = 0;i<n;i++){
			c[i] = sc.nextInt();
		}
		Arrays.sort(c);
		int j = 0;
		while(m>0){
			if(c[j] > m)break;
			m = m - c[j];
			j++;
			res++;
		}
		System.out.println(res);
	}
}
0