I code this pratha spoj problem but I am not getting the correct answer. Anyone please help in this. Here is the code link
Pratha Spoj Problem
- Please use long instead of int because there might be an overflow.
- You have not set the upper bound of the time correctly. It should be(p*(p + 1)max_rate)/2.
Here max_rate is the maximum rating of any chef. This upper bound is correct. Let the max rate be r.
Then time taken by that single chef to cook all the parathas is:
r + 2r + 3*r + … … … . pratha x r.
When you sum it up, it gives the above equation. - Use quadratic equations to calculate the number of parathas cooked by a chef in mid amount of time. It will give answer in O(1) and works extremely better than a for loop.
If my answer was able to clear your doubt, please mark the doubt as resolved.
Feel free to revert in case of any doubt.
@LP18Aug0068 Thanks for the reply. But I am not able to figure out the no. of prathas cooked by chef using Quadratic Equation given mid time.
@nikhil015
This is the number of paranthas:
ll k = (-1 + sqrt(1 + 4*d))/2;
Where d = 2mid/r
Lets suppose the chef is cooking n paranthas.
1r + 2* r+ . . . . . .nr <= mid
(rn*(n + 1)) <= 2mid
n(n + 1) <= 2*mid/r
solve this inequality.