結果

問題 No.1739 Princess vs. Dragoness (& AoE)
ユーザー ks2m
提出日時 2021-11-12 21:28:44
言語 Java
(openjdk 23)
結果
AC  
実行時間 1,879 ms / 3,000 ms
コード長 1,175 bytes
コンパイル時間 2,408 ms
コンパイル使用メモリ 79,400 KB
実行使用メモリ 59,588 KB
最終ジャッジ日時 2024-11-25 12:08:21
合計ジャッジ時間 37,645 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.PriorityQueue;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int a = Integer.parseInt(sa[1]);
		int b = Integer.parseInt(sa[2]);
		int x = Integer.parseInt(sa[3]);
		int y = Integer.parseInt(sa[4]);
		sa = br.readLine().split(" ");
		long[] h = new long[n];
		for (int i = 0; i < n; i++) {
			h[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		long yb = (long) y * b;
		long ok = 1000000000000000L;
		long ng = -1;
		while (Math.abs(ok - ng) > 1) {
			long mid = (ok + ng) / 2;
			PriorityQueue<Long> que = new PriorityQueue<>(Collections.reverseOrder());
			for (int i = 0; i < n; i++) {
				que.add(Math.max(h[i] - mid, 0));
			}
			for (int i = 0; i < a; i++) {
				que.add(Math.max(que.poll() - x, 0));
			}
			long sum = 0;
			for (long e : que) {
				sum += e;
			}
			if (sum <= yb) {
				ok = mid;
			} else {
				ng = mid;
			}
		}
		System.out.println(ok);
	}
}
0