Problem Link

Previous solution link

My above solution is running for some cases i.e., it was partially accepted , I made a small change in the code in Line 54:

temp+=(Math.ceil( ((float) (C[i]-mid))/(float)B[i]));

changed to

temp=temp-(mid/B[i])+A[i];

After doing this I got AC for all cases

New solution link

Please can anyone tell me why is this happening

In C/C++ , ceil() uses â€śdoubleâ€ť type as its argument and returns â€śdoubleâ€ť as well.Here, the value which is the argument of ceil() (c[i]-mid) can be as large as 10^18 which exceeds the range of â€śdoubleâ€ť. Hence,ceil() returns unexpected value and you got WA for large numbers (The case is same in Java)

1 Like

I tried it for 10^18 in c++ itâ€™s returning

1e+09 when i use ceil

and 1000000000 when i am using other approach

Can you share your code?

Anyway,

```
#include <bits/stdc++.h>
using namespace std;
int main()
{
long double c=1000000000000000000.76;
cout << ceil(c) <<endl;
}
```

This wonâ€™t output 1000000000000000001. Instead will output 1000000000000000000 (1e+18)

PS: Donâ€™t trust floating point numbers. They canâ€™t be stored/represented accurately and they betray when you need them the most

1 Like