After observing your code for quite some time, I could spot the error. Actually what happens is, when you find the correct output for a test case in the middle of the for loop and break it, and say there are more inputs to P and C remaining in the input file, those inputs will get considered as the X, Y, N, K for the next test case. Therefore, you will get wrong answer verdict. Your approach to solve this problem is correct though.
So the wisest thing to do here is to let the for loop run fully, then at the end, check if your flag ==1, then print “LuckyChef”, else print “UnluckyChef”.
thanks it worked.
please help me with this
I think somewhere your calculation is messed up. You’re finding the minimum instead of max?
Here’s my approach:
To start calculating the car’s with max speed, first we should set the maxSpeed to max(speeds)+1 where speeds is the array you store the val in. Now, as we traverse the array, we compare if the value stored in maxSpeed is greater than the current car value, if so, we increment the car count, and update the maxSpeed as the current car’s speed. The result will be the number of cars travelling with maximum speed.
Here’s my code. Veerendra Uppin's submission of Carvans | CodeChef
P.S: in my code i use the variable X to denote maxSpeed
also, check the editorial for this problem here:
this is the solution.