Working on sample input well

can you please help me to figure out what is wrong with my code

#include
using namespace std;
int main() {
int n,a,b,c,d,x,y;
cin>>n;
int sum=0;
int osum=0;
int esum=0;
int i=0;
while(i<n){
cin>>a>>b>>c>>d;
cin>>x>>y;
int u=0;
while(u<x){
int w;
sum=0;
cin>>w;
sum+=a*w;

if(sum>b){
	sum=b;
}
osum+=sum;
u++;

}
if(osum>c){
osum=c;
}
int k=0;
sum=0;
while(k<y){
sum=0;
int g=0;
cin>>g;
sum+=a*g;

if(sum>b){
sum=b;
}
esum+=sum;
k++;
}
if(esum>c){
esum=c;
}
i++;
int usum=osum+esum;
if(usum>d){
usum=d;
}
cout<<usum<<endl;
}
}

@Rajat-Sharma-2078329489142103 hey rajat please share your code through cb.lk/ide and I think for this question bhaiya already covered the optimized approach

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.