Test Case showing wrong answer

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]+c1
a2[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<max1
c1)
{
r[2]=(r[2]-c1a1[i1])+ c2;
}
r[4]=c3;
for(k=1;k<=a22;k++)
{
r[4]=r[4]+c1
a2[k];
}
if(c2<max2c1)
{
r[4]=(r[4]-c1
a2[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;
}
}

Plese save your code on the online ide

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.

I have already saved it.

i didn’t recieved the link for the solution

The link for my code is-

Hi keshav your code is not running for multiple test cases it is producing wrong answer.
10
1 3 7 19
2 3
2 5
4 4 4
4 3 2 1
1 3
798
1 2 3
100 100 8 100
3 5
7 94 12
100 1 47 0 42
680 871 347 800
10 100
872 156 571 136 703 201 832 213 15 333
465 435 870 95 660 237 694 594 423 405 27 866 325 490 255 989 128 345 278 125 708 210 771 848 961 448 871 190 745 343 532 174 103 999 874 221 252 500 886 129 185 208 137 425 800 34 696 39 198 981 91 50 545 885 194 583 475 415 162 712 116 911 313 488 646 189 429 756 728 30 985 114 823 111 106 447 296 430 307 388 345 458 84 156 169 859 274 934 634 62 12 839 323 831 24 907 703 754 251 938
671 644 748 783
100 10
520 363 816 957 635 753 314 210 763 819 27 970 520 164 195 230 708 587 568 707 343 30 217 227 755 277 773 497 900 589 826 666 115 784 494 467 217 892 658 388 764 812 248 447 876 581 94 915 675 967 508 754 768 79 261 934 603 712 20 199 997 501 465 91 897 257 820 645 217 105 564 8 668 171 168 18 565 840 418 42 808 918 409 617 132 268 13 161 194 628 213 199 545 448 113 410 794 261 211 539
147 3 178 680 701 193 697 666 846 389
4 43 490 945
63 92
0 0 0 0 0 0 6 5 18 0 6 4 0 17 0 19 0 19 7 16 0 0 0 9 10 13 7 0 10 16 0 0 0 0 0 14 0 14 9 15 0 0 2 0 0 0 0 5 0 0 0 11 11 0 0 0 0 0 10 12 3 0 0
0 12 0 18 7 7 0 0 9 0 0 13 17 0 18 12 4 0 0 14 18 20 0 0 12 9 17 1 19 0 11 0 5 0 0 14 0 0 16 0 19 15 9 14 7 10 0 19 19 0 0 1 0 0 0 6 0 0 0 6 0 20 1 9 0 0 10 17 5 2 5 4 16 6 0 11 0 8 13 4 0 2 0 0 13 10 0 13 0 0 8 4
1 1 3 4
2 3
1 1
1 1 1
100 100 1 100
10 10
100 100 100 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100 100 100
4 4 4 1
1 1
0
0
4 43 490 945
63 92
0 0 0 0 0 0 6 5 18 0 6 4 0 17 0 19 0 19 7 16 0 0 0 9 10 13 7 0 10 16 0 0 0 0 0 14 0 14 9 15 0 0 2 0 0 0 0 5 0 0 0 11 11 0 0 0 0 0 10 12 3 0 0
0 12 0 18 7 7 0 0 9 0 0 13 17 0 18 12 4 0 0 14 18 20 0 0 12 9 17 1 19 0 11 0 5 0 0 14 0 0 16 0 19 15 9 14 7 10 0 19 19 0 0 1 0 0 0 6 0 0 0 6 0 20 1 9 0 0 10 17 5 2 5 4 16 6 0 11 0 8 13 4 0 2 0 0 13 10 0 13 0 0 8 4
correct output: 12
1
16
694
783
945
4
2
0
945
your output: -14 524 25180 181-14 5-112 133 53 5

try some different approach.
if you want i can suggest you different approach

I have tried a different approach. All the test cases given by you are running on that code. But still when I’m submitting the code, it’s showing wrong answer. Please check my code.
Here is the link to my code-

the second last test case provided by me is not working. it should be 0 but in your code it is giving 1

It’s working now. Thank you.