1296:开餐馆
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 7 const int N=105; 8 int a[N],b[N],f[N]; 9 int main(){ 10 int t,n,k; 11 cin>>t; 12 while(t--){ 13 cin>>n>>k; 14 for(int i=1;i<=n;i++)scanf("%d",&a[i]); 15 for(int i=1;i<=n;i++)scanf("%d",&b[i]); 16 for(int i=1;i<=n;i++){ 17 int j=i-1; 18 for(;j>0;j--) 19 if(a[i]-a[j]>k)break; 20 f[i]=max(f[i-1],b[i]+f[j]); 21 } 22 cout<<f[n]<<endl; 23 } 24 return 0; 25 }