https://codeforces.com/contest/1408/problem/C
on local I m getting the correct ans but on codeforces it gives wrong ans.
https://codeforces.com/contest/1408/problem/C
on local I m getting the correct ans but on codeforces it gives wrong ans.
hello @kks2029
a)codeforces shows test cases , u can check where ur code fails
b) also pls explain ur logic
I am using binary search for the problem
The distancecovered function calculates distance travelled by both
then I am checking if deir distance is equal greater or lesser
I have updated the testcase on ide showing wa 2nd test case i giving 99…99.999
expected answer 361644086.1250000
any update on this why I am receivng this error
so u r trying to binary search on time.
u are checking after time t final position of both the cars.
if they cross then u r looking for [0…mid] range otherwise u r looking in [mid+1,l] range right?
if this is ur logic then it is correct.
the issue is with precision.

here instead of dividing by i .
u can check (flag[i]-flag[i-1)>= t * i // this way u can avoid division and hence no precision error.
similarly try in other loop and see if it is working or not
I didnt get the precision thing can you explain?
in line 11 u r comparing t1 > = t
now replace t1 with its value and move all the terms in numberator by transfering it to other side
In the cb ide i do get the correct anser bt in cfs it doesnt pass
…
it becuase of strict precision…
check this->
nope doesnt work i have updated the code
Yup it has implemented the same logic
…
that is what i am saying your logic is correct.
the issue is with precision.
This code got accepted I just initialized the double t1 and t2
can you deduce something from this?
…
yeah , because double can store more precise value then int or float.
what should be the general rule in such question because double has prcesion upto 15 places and here they eanted upto 7 places also I had to use long double
…
try to avoid division as much as u can in precision related question by simplying the expression (if division is there bring it to numerator by transfering it to other side).
if in question they explicity mentioned that they want want precise value upto some digit then blindly use double . becuase float can cause issue due to less precision capacity.
never use int if question is related with precision becuase int only store integer part
haan bt here I was using double only before and shifting the numerator is still not working here. can you make corrections here?