結果

問題 No.1739 Princess vs. Dragoness (& AoE)
ユーザー MasKoaTS
提出日時 2021-11-12 22:29:26
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,475 bytes
コンパイル時間 3,801 ms
コンパイル使用メモリ 254,796 KB
最終ジャッジ日時 2025-01-25 17:04:55
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23 WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <math.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, l, n) for (int i = (l); i < (n); i++)
#define max(p, q) ((p) > (q) ? (p) : (q))
#define min(p, q) ((p) < (q) ? (p) : (q))
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define lb lower_bound;
#define ub upper_bound;
//#define lb(A, x) (ll)(lower_bound(all(A), x) - A.begin())
//#define ub(A, x) (ll)(upper_bound(all(A), x) - A.begin())
using ll = long long;
using P = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T> >;
template <class T>
const ll INF = 1000000000000000001;
const int inf = 1001001001;
const ll mod = 1000000007;
const ll MOD = 998244353;

bool func(V<ll>&h,ll n,ll a,ll b,ll x,ll y,ll k) {
	set<ll> st{};
	rep(i, 0, n) {
		st.insert(-h[i] + k);
	}
	
	rep(i, 0, a) {
		auto it = st.begin();
		ll t = *it + x;
		//cout << *it << endl;
		st.erase(it);
		st.insert(t);
	}
	ll s = 0;
	while (st.empty() == false) {
		auto it = st.begin();
		auto t = -(*it);
		st.erase(it);
		s += max(0, (ll)t);
	}
	if (s <= (ll)y * (ll)b) {
		return true;
	}
	return false;
}

int main(void) {
	ll n, a, b, x, y;	cin >> n >> a >> b >> x >> y;
	V<ll> h(n);
	rep(i, 0, n) {
		cin >> h[i];
	}

	ll ok = 1000000000;
	ll ng = -1;
	while (ok - ng > 1) {
		ll k = (ok + ng) / 2;
		if (func(h, n, a, b, x, y, k)) {
			ok = k;
		}
		else {
			ng = k;
		}
	}

	cout << ok << endl;
	return 0;
}
0