結果

問題 No.156 キャンディー・ボックス
ユーザー 37zigen
提出日時 2016-03-31 18:01:39
言語 Java
(openjdk 23)
結果
AC  
実行時間 389 ms / 2,000 ms
コード長 529 bytes
コンパイル時間 1,727 ms
コンパイル使用メモリ 75,568 KB
実行使用メモリ 45,916 KB
最終ジャッジ日時 2024-07-05 15:48:17
合計ジャッジ時間 8,014 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder156;
import java.util.PriorityQueue;
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();
		PriorityQueue<Integer> pq=new PriorityQueue<>();
		for(int i=0;i<n;i++){
			pq.add(sc.nextInt());
		}
		int count=0;
		for(int i=0;i<m;i++){
			int nnn=pq.poll();
			nnn--;
			if(nnn==0){
				count++;
				if(pq.isEmpty())break;
				continue;
			}
			pq.add(nnn);
			
		}
		System.out.println(count);
	}
}
0