結果

問題 No.1739 Princess vs. Dragoness (& AoE)
ユーザー 👑 hos.lyrichos.lyric
提出日時 2021-11-12 21:34:25
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 1,689 ms / 3,000 ms
コード長 2,111 bytes
コンパイル時間 857 ms
コンパイル使用メモリ 120,664 KB
実行使用メモリ 7,832 KB
最終ジャッジ日時 2023-09-04 14:54:42
合計ジャッジ時間 36,420 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 37 ms
4,376 KB
testcase_04 AC 1,524 ms
7,408 KB
testcase_05 AC 1,684 ms
7,524 KB
testcase_06 AC 964 ms
7,096 KB
testcase_07 AC 43 ms
4,376 KB
testcase_08 AC 478 ms
5,692 KB
testcase_09 AC 749 ms
6,412 KB
testcase_10 AC 831 ms
5,516 KB
testcase_11 AC 645 ms
5,296 KB
testcase_12 AC 62 ms
4,376 KB
testcase_13 AC 992 ms
6,248 KB
testcase_14 AC 1,106 ms
5,748 KB
testcase_15 AC 1,212 ms
7,596 KB
testcase_16 AC 871 ms
4,380 KB
testcase_17 AC 635 ms
4,896 KB
testcase_18 AC 1,001 ms
6,128 KB
testcase_19 AC 466 ms
4,840 KB
testcase_20 AC 199 ms
4,380 KB
testcase_21 AC 859 ms
6,044 KB
testcase_22 AC 1,141 ms
7,052 KB
testcase_23 AC 1,686 ms
7,368 KB
testcase_24 AC 1,675 ms
7,368 KB
testcase_25 AC 1,680 ms
7,388 KB
testcase_26 AC 1,634 ms
7,412 KB
testcase_27 AC 1,678 ms
7,556 KB
testcase_28 AC 1,631 ms
7,572 KB
testcase_29 AC 1,688 ms
7,776 KB
testcase_30 AC 1,689 ms
7,832 KB
testcase_31 AC 1,628 ms
7,792 KB
testcase_32 AC 1,630 ms
7,324 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 4 ms
4,380 KB
testcase_35 AC 4 ms
4,376 KB
testcase_36 AC 6 ms
4,376 KB
testcase_37 AC 4 ms
4,376 KB
testcase_38 AC 5 ms
4,376 KB
testcase_39 AC 9 ms
4,380 KB
testcase_40 AC 4 ms
4,376 KB
testcase_41 AC 5 ms
4,380 KB
testcase_42 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }




void main() {
  try {
    for (; ; ) {
      const N = readInt();
      const A = readInt();
      const B = readInt();
      const X = readLong();
      const Y = readLong();
      auto H = new long[N];
      foreach (i; 0 .. N) {
        H[i] = readLong();
      }
      
      bool check(long k) {
        BinaryHeap!(Array!long) que;
        foreach (i; 0 .. N) {
          que.insert(H[i] - k);
        }
        foreach (_; 0 .. A) {
          const h = que.front;
          que.removeFront;
          que.insert(h - X);
        }
        long sum;
        for (; !que.empty; ) {
          const h = que.front;
          que.removeFront;
          sum += max(h, 0);
        }
        return (sum <= B * Y);
      }
      
      long lo = -1, hi = 10L^^9 + 10;
      for (; lo + 1 < hi; ) {
        const mid = (lo + hi) / 2;
        (check(mid) ? hi : lo) = mid;
      }
      writeln(hi);
    }
  } catch (EOFException e) {
  }
}
0