I have written the code for test ramu problem. It seems correct to me, and the given test cases are running. However, when I’m submitting the code, it’s showing wrong answer. Can you please tell me what is the problem with my code?
I am posting my code below-
#include
#include<math.h>
using namespace std;
int main()
{
int i,n,c1,c2,c3,c4,a11,a22,r[5],a1[1000],a2[10000],max1=0,max2=0,max=0,j,k,i1=1,i2=1,min=0;
cin>>n;
for(i=0;i<n;i++)
{
cin>>c1>>c2>>c3>>c4;
cin>>a11>>a22;
for(j=1;j<=a11;j++)
cin>>a1[j];
for(k=1;k<=a22;k++)
cin>>a2[k];
max1=a1[1];
for(j=2;j<=a11;j++)
if(a1[j]>max1)
{
max1=a1[j];
i1=j;
}
max2=a2[1];
for(k=2;k<=a22;k++)
if(a2[k]>max2)
{
max2=a2[j];
i2=k;
}
r[1]=c2;
if(max1>max2)
{
for(j=1;j<=a11;j++)
{
if(j!=i1)
r[1]=r[1]+c1a1[j];
}
for(k=1;k<=a22;k++)
{
r[1]=r[1]+c1a2[k];
}
}
else
{
for(j=1;j<=a11;j++)
{
r[1]=r[1]+c1*a1[j];
}
for(k=1;k<=a22;k++)
{
if(k!=i2)
r[1]=r[1]+c1*a2[k];
}
}
r[2]=c3;
for(j=1;j<=a11;j++)
{
r[2]=r[2]+c1a1[j];
}
if(c2<max1c1)
{
r[2]=(r[2]-c1a1[i1])+ c2;
}
r[4]=c3;
for(k=1;k<=a22;k++)
{
r[4]=r[4]+c1a2[k];
}
if(c2<max2c1)
{
r[4]=(r[4]-c1a2[i2])+ c2;
}
if(r[4]<r[2])
r[2]=r[4];
r[3]=c4;
r[0]=0;
for(j=1;j<=a11;j++)
{
r[0]=r[0]+c1*a1[j];
}
for(k=1;k<=a22;k++)
{
r[0]=r[0]+c1*a2[k];
}
min=r[0];
for(j=1;j<=3;j++)
{
if(r[j]<min)
min=r[j];
}
cout<<min<<endl;
}
}