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


#1

Can someone tell me what is wrong in this


[1]


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

#2

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

Thank you…:slight_smile:


#4

Sure thing :slight_smile: