I am lacking something to pass the last test case, so please help me in thinking about the edge case in which my code may fail. I don’t want to unlock the test case as i won’t get any points then.
Hint for the 5th test case
@7nishit could you tell me your logic or send me your code so that i can check where your code may fail.
My code is in collaborate mode, so you should be able to see it
#include #include using namespace std; int main() { long int T,c1,c2,c3,c4,n,m,x; //needed variables long int rickshawRides, cabRides, individualCab,individualRickshaw,oneRickRides,oneCabRides; long int totalRickshaw,totalCab; cin>>T; vector a,b; for(int i=0;i<T;i++) { totalCab=0; totalRickshaw=0; cabRides=0; rickshawRides=0; individualCab=0; individualRickshaw=0; cin>>c1>>c2>>c3>>c4; cin>>m>>n; for(int j=0;j<m;j++) { cin>>x; a.push_back(x); rickshawRides+=x; } for(int j=0;j<n;j++) { cin>>x; b.push_back(x); cabRides+=x; } //for rickshaw individualRickshaw=c1*rickshawRides; //cout<<“Individual Rick”<<individualRickshaw<<endl; oneRickRides=c2+(rickshawRides-a[0])*c1; for(int i=1;i<m;i++) { oneRickRides=min(oneRickRides,c2+(rickshawRides-a[i])c1); } //cout<<“All rides on one:”<<oneRickRides<<endl; totalRickshaw=min(c3,min(individualRickshaw,oneRickRides)); //cout<<“Total Rick:”<<totalRickshaw<<endl; //for cab individualCab=c1cabRides; //cout<<“Individual Cab”<< individualCab<<endl; oneCabRides=c2+(cabRides-b[0])*c1; for(int i=1;i<n;i++) { oneCabRides=min(oneCabRides,c2+(cabRides-b[i])*c1); } //cout<<“All rides on one:”<<oneCabRides<<endl; totalCab=min(c3,min(individualCab,oneCabRides)); //cout<<“Total Cab:”<<totalCab<<endl; //combined for both rickshaw and cab cout<<min(totalCab+totalRickshaw,c4)<<endl; } return 0; }
@7nishit i told you to send it to me via (https://ide.codingblocks.com/) here it is not getting paste correctly.
@7nishit first lets talk about rikshaw, in your code you are buying ticket c2 for only one rickshaw (since you are subtracting only one a[i] from all the rickshawrides and adding c2 only once and for rest all the rickshaw you are buying c1) but cost of rickshaw for each a[i] will be optimal with min( c2 or a[i]*c1). so you have to check for each rickshaw should ramu use a[i]*c1 or c2 add this all then compare it with c3.
same goes for cab too.
I have included the a[i]c1 in the above case where I am buying individual tickets for all the rickshaw rides…it’s there in the line individualRickshaw=c1rickshawRides; ,in the second case i am buying a all ride pass for one rickshaw at a time and then comparing all the costs (all oneRickRides)…and what you are saying …i.e to compare the two kinds of cost…I have done that in the end while calculating totalRickshaw… totalRickshaw=min(c3,min(individualRickshaw,oneRickRides)); … I hope i made myself clear:)
@7nishit take a look at this code you will understand how i am saying it to compare (https://ide.codingblocks.com/s/189745) .
Thanks! Got your point.