結果

問題 No.156 キャンディー・ボックス
ユーザー YamaKasa
提出日時 2018-04-26 00:05:28
言語 Java
(openjdk 23)
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 577 bytes
コンパイル時間 2,896 ms
コンパイル使用メモリ 75,108 KB
実行使用メモリ 54,496 KB
最終ジャッジ日時 2024-07-05 16:17:46
合計ジャッジ時間 9,442 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int M = scan.nextInt();
		int []C = new int[N];
		for(int i = 0; i < N; i++) {
			C[i] = scan.nextInt();
		}
		scan.close();
		Arrays.sort(C);
		int ans = 0;
		for(int i = 0; i < N; i++) {
			M -= C[i];
			ans ++;
			if(M == 0) {
				System.out.println(ans);
				System.exit(0);
			}else if(M <= 0) {
				System.out.println(ans - 1);
				System.exit(0);
			}
		}
		System.out.println(ans);
	}
}
0