結果

問題 No.1739 Princess vs. Dragoness (& AoE)
ユーザー CuriousFairy315CuriousFairy315
提出日時 2021-11-12 22:02:11
言語 Java
(openjdk 23)
結果
AC  
実行時間 2,939 ms / 3,000 ms
コード長 836 bytes
コンパイル時間 2,618 ms
コンパイル使用メモリ 79,112 KB
実行使用メモリ 69,096 KB
最終ジャッジ日時 2024-11-25 18:34:36
合計ジャッジ時間 57,440 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int N = sc.nextInt(), A = sc.nextInt(), B = sc.nextInt(), X = sc.nextInt(), Y = sc.nextInt();
			int[] H = new int[N];
			for (int i = 0;i < N;++ i) H[i] = sc.nextInt();
			int ng = -1, ok = 1_000_000_000;
			while(ok - ng > 1) {
				int mid = ok + ng >> 1;
				PriorityQueue<Integer> pq = new PriorityQueue<>(Comparator.reverseOrder());
				for (int i : H) pq.add(i - mid);
				for (int i = 0;i < A;++ i) pq.add(pq.poll() - X);
				long sum = 0;
				while(!pq.isEmpty()) {
					if (pq.peek() > 0) sum += pq.poll();
					else break;
				}
				if ((long)B * Y >= sum) ok = mid;
				else ng = mid;
			}
			System.out.println(ok);
		}
	}
}
0