ZZULIOJ 2829: 闯关游戏
#include<bits/stdc++.h>
using namespace std;
int f[6010];
signed main()
{
int T;cin>>T;
while(T--)
{
memset(f,0,sizeof f);
int n,H;cin>>n>>H;
int res=0,now=0,flag=0;
for(int i=1;i<=n;i++)
{
int A,B,C,D;cin>>A>>B>>C>>D;
if(flag) continue;
if(A>C) {swap(A,C);swap(B,D);}
if(H<A)
{
flag=1;
continue;
}
now+=B;H-=A;
C-=A;D-=B;
for(int j=H;j>=C;j--)
f[j]=max(f[j],f[j-C]+D);
res=max(res,now+f[H]);
}
cout<<res<<endl;
}
return 0;
}