SNTEMPLE : What is wrong with this code, it is giving WA.

Can someone tell me what is wrong in this


[1]


  [1]: https://www.codechef.com/viewsolution/13896462

It is just integer overflow. As n ≤ 105 and h ≤ 109, in the worst case sum would have to hold the value 105 × 109 = 1014, which does not fit in int type. Use long instead for sum. Also max*max overflows, which can be fixed by either using long for max too, or changing max*max to (long)max*max.

3 Likes

Thank you…:slight_smile:

2 Likes

Sure thing :slight_smile: