Is my logic correct?

Hello everyone. I have recently joined joined codechef and am new to the forum. Please include in comments if I could improve my communication about my problem in any way.
Now for my problem:
It is a problem of the December long challenge.
My solution:

I used basic maths
first i calculated the number of days that the vaccine is produced by each company
Comp 1: d - D1 +1
Comp 2: d - D2 +1
then i multiplied them by number of vaccines per day and solved the inequation
(d-D1+1)*V1 + (d-D2+1)*V2 >=P

this came to:
d > = (P+ D1V1 + D2V2 - V1 - V2) / (V1+V2)
so i calculated the RHS and used ceil() so that sould give me minimum d. But the answer is not matching for 1 test case.
Please tell me if there is some mistake in logic or code.
All the past solutions i checked are complicated yet they give correct answers.
So I am worried if I missed something.

If the first company finishes making the vaccine, even before the second company starts manufacturing, then you will have some problems with your equations. Because D2>d, there will be a negative number of days the second company will be working.
Your equation should be:

max(0,d-D1+1) \times V1 + max(0,d-D2+1) \times V2 \geq P

Since the constraints are smaller, you will be better off just checking for all d.

1 Like

Thank you very much.