結果

問題 No.156 キャンディー・ボックス
ユーザー ぴろず
提出日時 2015-02-26 23:26:09
言語 Java
(openjdk 23)
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 480 bytes
コンパイル時間 2,224 ms
コンパイル使用メモリ 74,452 KB
実行使用メモリ 54,208 KB
最終ジャッジ日時 2024-07-05 08:39:02
合計ジャッジ時間 7,775 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

package no156;

import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] c = new int[n];
		for(int i=0;i<n;i++) {
			c[i] = sc.nextInt();
		}
		Arrays.sort(c);
		int ans = 0;
		for(int i=0;i<n;i++) {
			int x = Math.min(m,c[i]);
			c[i] -= x;
			m -= x;
			if (c[i] == 0) {
				ans++;
			}
		}
		System.out.println(ans);
	}

}
0