Problem A:

Hey friends i'm aryan kabir, let me explaine my solution choose a subset in a, choose a subset in b, make their sum w and abs (sumai-sumbi) <= k, and ask for the number of solutions.


Knapsack problem,
w = sumai + sumbi, da [j] represents the number of solutions when a is constructed and j, and db [j] is the number of solutions when it is constructed and j.
So enumerate the possible sumai, and then correspond to w-sumai, then ans = sigma (da [sumai] * db [w-sumai]) and then find da, the method of db is 01 backpack,


complexity O (n * w)

#include<iostream>
#include<algorithm>
#include<
cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
#define MOD 1000000007ll//means follow output mod section
int T,n,m,K,W;
int a[160],b[160];
int Abs(int x)
{
return x<0 ? (-x) : x;
}
ll f[15010],g[15010];
int main()
{
scanf("%d",&T);
for(;T;--T)
{
scanf("%d%d%d%d",&n,&m,&K,&W);
for(int i=1;i<=n;++i)
scanf("%d",&a[i]);
for(int i=1;i<=m;++i)
scanf("%d",&b[i]);
memset(f,0,sizeof(f));
memset(g,0,sizeof(g));
f[0]=1;
for(int i=1;i<=n;++i)
for(int j=15000;j>=0;--j)
if(a[i]+j<=15000)
f[j+a[i]]=(f[j+a[i]]+f[j])%MOD;
g[0]=1;
for(int i=1;i<=m;++i)
for(int j=15000;j>=0;--j)
if(b[i]+j<=15000)
g[j+b[i]]=(g[j+b[i]]+g[j])%MOD;
ll ans=0;
for(int i=0;i<=W;++i)
if(Abs(W-i-i)<=K)
ans=(ans+f[i]*g[W-i]%MOD)%MOD;
cout<<ans<<endl;
}
return 0;
}