A slight help for solving SNUG_FIT

Hey guys. I have wrote a code for the snug_fit challenge but it shows wrong answer. My example test input gave the correct answer. But i think it doesnt cover all the situations. Can anyone point out the error in the logic?

https://www.codechef.com/viewsolution/30012631

Just change sum to long long int

1 Like

Ohhh… That worked. Thank you so much for ur help. Realized that something as stupid as that can make or break a whole program.

If you want to check whether your code is overflowing, you can use

#pragma GCC optimize "trapv"

At the top of the code.
It will give a runtime error instead of Wrong answer.

3 Likes

What does that do? I know just the basics of CPP coding.

1 Like

It gives Runtime error if something overflows, instead of wrong answer.

Ohh… Got it

You may go through this thread by @ssjgz. It has some nice debugging tips. :slightly_smiling_face:

1 Like