Help Ramu question..Test case not passing

#include
using namespace std;
int main() {
int c1,c2,c3,c4;
int m,n;
int i,a;
int N,SingleRsum,SingleCsum,USRsum,USCsum,URsum,UCsum,Usum,minR,minC,sumR=0,sumC=0;
cin>>N;
while(N–>0){
SingleRsum=0,SingleCsum=0,USRsum=0,USCsum=0,URsum=0,UCsum=0,Usum=0;
cin>>c1>>c2>>c3>>c4;
cin>>n>>m;
Usum=c4;
for(i=0;i<n;i++){
cin>>a;
SingleRsum=c1a;
USRsum= c2;
URsum=c3;
minR=SingleRsum<USRsum?SingleRsum:USRsum;
sumR+=minR;
}
if(sumR>URsum)
sumR=URsum;
for(i=0;i<m;i++){
cin>>a;
SingleCsum=c1
a;
USCsum=c2;
UCsum=c3;
minC=SingleCsum<USCsum?SingleCsum:USCsum;;
sumC+=minC;
}
if(sumC>UCsum)
sumC=UCsum;
if(sumR+sumC<Usum)
cout<<sumR+sumC;
else
cout<<Usum;
cout<<endl;
}
return 0;
}

Hello @dbhavanishankar89,

Please, share your code using Online Coding Blocks IDE.
The way you have shared it, is introducing many syntax errors to it.
Also, add some comments in your code explaining these variables you have used.

Steps:

  1. Paste your code on IDE.
  2. Save it there.
  3. Share the URL generated.

Waiting for your code.:slightly_smiling_face:

I observed your code and found that you are missing some cases:

You are required to find cost of each of the cases:

  1. when he pay c1 for each ride he took in a rickshaw and cab
    i.e. c1*(total rikshaw + total cabs)

  2. When he pay c2 for each rikshaw type and each cab type
    i.e c2*(m+n)

  3. When he pays c3 for all rikshaws and for all cabs
    i.e. c3*(1+1)

  4. When he pays only c4 for all rickshaws and cabs
    i.e. c4

  5. You have to consider the combinations also.
    example: if c1 is 1 and c2 is 5,
    then you should pay c1 for rickshaw or cab rides less than 5.
    and for rides greater or equal to 5, paying c2 is feasable.

Hope, this would help.
Give a like, if you are satisfied.

Can you tell me the case where iam going wrong …I mean with an example.

No iam not getting.Please tell me where iam going wrong in my code with an example.

Hello @dbhavanishankar89,

I asked you to share your original code rather pasting the above in the IDE.
As it didn’t help.
I have corrected all the syntax errors.

You should feel good as the logic of your code is correct. It is satisfying all the above specified cases.
Then, why is it giving error?

Let’s understand this with the help of the example:
2
1 1 1 1
2 2
1 1
1 1
1 1 16 90
2 2
1 1
1 1
Expected Output:
1
4
Your Output:
1
6

Reason:
After running the first testcase:
sumR=1 and sumC=1
Now, here comes the issue:
As you are not initializing sumR and sumC in the start of further testcases.
Thus, it is introducing error due to value stored in previous testcase.

Solution:
sumR=0,sumC=0;
add above inside the while loop at the start.

Hope, this would help.
Give a like, if you are satisfied.

1 Like

Thanks a lot.Didn’t see that.One simple mistake made me wait whole day:disappointed_relieved::disappointed_relieved:.
Thank you.
Is my solution optimised one or still we can implement in better way.
I want your review .

Yup, It is optimized.
As per what you have learnt till now in your course, it is the optimized solution.
Though you are using many unnecessary variables that you can easily avoid.:wink: