#include #define Re register int const int N=7003,M=7003; int n,h,t,V,mp,tmp,v[N],w[N],c[N],Q[N],K[N],dp[M]; inline void in(Re &x){ Re fu=0;x=0;char ch=getchar(); while(ch<'0'||ch>'9')fu|=ch=='-',ch=getchar(); while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar(); x=fu?-x:x; } inline int max(Re a,Re b){return a>b?a:b;} inline int min(Re a,Re b){return amin(c[i],V/v[i]))++h; dp[p*v[i]+r]=max(dp[p*v[i]+r],Q[h]+p*w[i]); } } printf("%d",dp[V]); }