結果

問題 No.156 キャンディー・ボックス
ユーザー uafr_cs
提出日時 2015-05-15 13:51:22
言語 Java
(openjdk 23)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 542 bytes
コンパイル時間 2,298 ms
コンパイル使用メモリ 74,408 KB
実行使用メモリ 41,664 KB
最終ジャッジ日時 2024-07-05 09:15:19
合計ジャッジ時間 7,176 ms
ジャッジサーバーID
(参考情報)
judge5 / 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);
		
		final int N = sc.nextInt();
		final int M = sc.nextInt();
		
		int[] array = new int[N];
		for(int i = 0; i < N; i++){
			array[i] = sc.nextInt();
		}
		Arrays.sort(array);
		for(int i = 1; i < N; i++){
			array[i] += array[i - 1];
		}
		
		int pos = Arrays.binarySearch(array, M);
		if(pos < 0){
			pos = -(pos + 1);
		}else{
			pos++;
		}
		
		System.out.println(pos);
		
		
	}
	
}
0