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

Can someone tell me what is wrong in this



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.


Thank you…:slight_smile:


Sure thing :slight_smile: