### Kanao's blog

By Kanao, history, 2 months ago,

Can someone help me with Step-2 C: Very Easy Task

My Approach: if the task can be done in T time, then 1(good) else 0 (bad). So, making 1 copy of the original document will take min(x,y) time, and then both copy machines can simultaneously work.

we need to check whether n copies can be made in T time or not, if I am updating T1 = T-min(x,y) and then checking that can I make n-1 copies in T1 time. Then find the first occurrence of 1 using binary search. It is throwing me an error "Wrong Answer on test case 5"

Code

Actual Approach : we need to check whether n-1 copies can be made in T time or not. Then, by using binary search find the first occurrence of 1 as it will be the least time to make n-1 copies, and then adding min(x,y) as it will be the time to make the copy of original.

AC Code

I dont know, where am I making mistake, both logics seems similar to me.

• -4

 » 2 months ago, # | ← Rev. 3 →   0 Your logic is correct, the implementation is a bit off. In the check function, there might be a case when "mid" becomes negative, in that case if abs(mid) is less than "x" and "y", "res" would be "0", losing the negativeness. C++ treats $-a/b$ as 0, when $a < b$, the negativity is not preserved. To ensure that just make sure mid is non-negative. AC Code
•  » » 2 months ago, # ^ |   0 hey, thanks alot!I will check this out, thanks for helping i was struggling with this since a very long time.