結果

問題 No.156 キャンディー・ボックス
ユーザー aaaaasatori
提出日時 2018-02-15 19:44:19
言語 Java
(openjdk 23)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 477 bytes
コンパイル時間 3,276 ms
コンパイル使用メモリ 74,532 KB
実行使用メモリ 41,776 KB
最終ジャッジ日時 2024-07-05 16:13:02
合計ジャッジ時間 8,539 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class No156 {
	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 sum = 0;
		int x = 0;
		while(true) {
			sum += C[x];
			if(sum >= M) {
				if(sum == M) {
					x++;
				}
				break;
			}
			x++;
		}
		
		System.out.println(x);
	}
}
0