結果

問題 No.156 キャンディー・ボックス
ユーザー k_kadora
提出日時 2015-05-27 03:37:40
言語 Java
(openjdk 23)
結果
AC  
実行時間 151 ms / 2,000 ms
コード長 393 bytes
コンパイル時間 3,865 ms
コンパイル使用メモリ 75,248 KB
実行使用メモリ 41,592 KB
最終ジャッジ日時 2024-07-05 09:15:56
合計ジャッジ時間 9,340 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

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