結果

問題 No.156 キャンディー・ボックス
ユーザー rf141
提出日時 2015-08-10 02:33:41
言語 Java
(openjdk 23)
結果
AC  
実行時間 152 ms / 2,000 ms
コード長 575 bytes
コンパイル時間 3,723 ms
コンパイル使用メモリ 74,992 KB
実行使用メモリ 41,948 KB
最終ジャッジ日時 2024-07-05 09:18:20
合計ジャッジ時間 8,879 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
public class candy{
	public static void main(String... args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		System.out.println(docandy(n,m,scan));
	}
	public static int docandy(int n,int m,Scanner scan){
		int[] candyBox = new int[n];
		for(int i = 0; i < n; i++){
			candyBox[i] = scan.nextInt();
		}
		Arrays.sort(candyBox);
		int count=0,now=0;
		while(count<m && now < n){
			if(candyBox[now]!=0){
				count++;
				candyBox[now]-=1;	
			}
			if(candyBox[now]==0){
				now++;
			}
		}
		return now;
	}
}
0