結果

問題 No.1736 Princess vs. Dragoness
ユーザー inksamuraiinksamurai
提出日時 2021-11-12 22:56:22
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,174 bytes
コンパイル時間 1,526 ms
コンパイル使用メモリ 168,992 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-25 20:54:15
合計ジャッジ時間 2,539 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define sz(a) (ll)a.size()
#define all(a) a.begin(),a.end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define crep(i,x,n) for(ll i=x;i<n;i++)
#define drep(i,n) for(ll i=n-1;i>=0;i--)
#define vec(...) vector<__VA_ARGS__>
#define _3pPbCt8 ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
using pii=pair<ll,ll>;
using vi=vector<ll>;

int main(){
_3pPbCt8;
	ll n,ca,cb,x,y;
	cin>>n>>ca>>cb>>x>>y;
	vi a(n);
	rep(i,n){
		cin>>a[i];
	}
	auto f=[&](ll need)->ll{
		ll now=0;
		rep(i,n){
			// h - x * e <= need
			// (h - need)/x <= e
			ll e=max(0ll,(a[i]-need)/x);
			if(a[i]-e*x>need) e++;
			now+=e;
		}
		return (now<=ca);
	};
	ll l=0,r=1e9,c=-1;
	while(l<=r){
		ll m=(l+r)>>1;
		if(f(m)){
			c=m;
			r=m-1;
		}else{
			l=m+1;
		}
	}
	ll need=c;
	rep(i,n){
		if(a[i]>c){
			ll e=max(0ll,(a[i]-need)/x);
			if(a[i]-e*x>need) e++;
			if(ca>=e){
				a[i]-=e*x;
				ca-=e;
			}
		}
		a[i]=max(a[i],0ll);
	}
	ll _sum=0;
	rep(i,n){
		_sum+=a[i];
	}
	if((_sum+y-1)/y<=cb){
		cout<<"Yes\n";
	}else{
		cout<<"No\n";
	}
//	
	return 0;
}
0