diff --git a/src/7/25/T639173.cpp b/src/7/25/T639173.cpp index c66fcee..cc01c31 100644 --- a/src/7/25/T639173.cpp +++ b/src/7/25/T639173.cpp @@ -1,42 +1,34 @@ -/* -2 10 7 11 -2 10 -6 1 - -n=2, W=10, B=7, X=11 -c[1]=2,c[2]=10 -cost[1]=6,cost[2]=1 - -*/ - #include #include #include #include +#include +#include #include using ll = int64_t; -#define il static inline -ll n,w,b,x,ans=0; +ll n,w,b,x; std::vector c,cost; +constexpr ll inf = std::numeric_limits::min(); -il void dfs(ll nn,ll nw,ll nb,ll nc){ - if(nn>n){ - ans=std::max(ans,nc); - return; +static inline ll dp(ll i,ll j){ + if(i==0){ + if(j==0)return w; + else return inf; } - for(ll i=0;i<=c[nn];i++){ - if(nw> vdp(n+1,std::vector(10000+1,inf)); + if(vdp[i][j]!=inf)return vdp[i][j]; + for(ll k=0;k<=c[i];k++){ + if(j-k<0||dp(i-1,j-k)<0)continue; + vdp[i][j]=std::max(vdp[i][j],std::min(dp(i-1, j-k)+x,w+(j-k)*b)-cost[i]*k); } + return vdp[i][j]; } int main(){ std::iostream::sync_with_stdio(false); std::cin.tie(nullptr); - std::cout.tie(nullptr); - std::cin>>n>>w>>b>>x; c.resize(n+1); cost.resize(n+1); @@ -46,6 +38,11 @@ int main(){ for(ll i=1;i<=n;i++){ std::cin>>cost[i]; } - dfs(1, w, b, 0); - std::cout<=0;i--){ + if(dp(n, i)>=0){ + std::cout<