結果

問題 No.156 キャンディー・ボックス
ユーザー ohagi_1182
提出日時 2017-10-18 21:02:11
言語 Java
(openjdk 23)
結果
AC  
実行時間 132 ms / 2,000 ms
コード長 417 bytes
コンパイル時間 2,057 ms
コンパイル使用メモリ 74,340 KB
実行使用メモリ 41,592 KB
最終ジャッジ日時 2024-07-05 16:07:00
合計ジャッジ時間 7,343 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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 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++) {
			m -= c[i];
			if(m >= 0) ans++;
		}
		System.out.println(ans);
 	}
}

0