結果

問題 No.1739 Princess vs. Dragoness (& AoE)
ユーザー Shirotsume
提出日時 2021-10-29 16:47:51
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 380 ms / 3,000 ms
コード長 1,260 bytes
コンパイル時間 1,034 ms
コンパイル使用メモリ 82,436 KB
最終ジャッジ日時 2025-01-25 08:12:04
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
ll max(ll a, ll b){
    if(a > b){
        return a;
    }
    else return b;
}
ll sumVector(const vector<ll>& v){
  ll sum = 0;
  for(size_t i=0; i<v.size(); i++){
    sum += v[i];
  }
  return sum;
}
int is_ok(ll k, ll n, ll a, ll b, ll x, ll y, vector<ll> h){
    vector<ll> c(n, 0);
    for(int i = 0; i < n; i++){
        c[i] = max(0, h[i] - k);
    }
    for(int i =0; i < n; i++){
        ll d = min(a, c[i] / x);
        a -= d;
        c[i] -= x * d;
    }
    sort(c.begin(), c.end(), greater<ll>());
    for(int i = 0; i < n; i++){
        if(a > 0){
            c[i] = 0;
            a--;
        }
    }
    if (sumVector(c) <= b * y){
        return 1;
    }
    else return 0;
    
}
using namespace std;
int main(void){
    // Your code here!
    ll n, a, b, x, y;
    cin >> n >> a >> b >> x >> y;
    vector<ll> h(n, 0);
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    ll ok = 10e9;
    ll ng = -1;
    while(ok - ng > 1){
        ll mid = (ok + ng) / 2;
        if(is_ok(mid, n, a, b, x, y, h)){
            ok = mid;
        }
        else ng = mid;
    }
    cout << ok << endl;
    
}
0