Why INT_MAX doesn't give AC

In the problem, FFL of LTIME83B, using comparison with INT_MAX for getting the smallest element gives WA, whereas comparing with 100 gives AC. Why is it so?

It’s just comparison, so why is it be considered with the constraint.

AC submission
WA submission

2 Likes

Its not just a comparison, when you are using INT_MAX and checking the condition:

if(ans1+ans2+s>100)
     cout << "no\n";

the ans1 + ans2 part overflows which in turn gives WA.

Refer to the test-cases given here: Getting wrong answer in FFL April Lunchtime - #3 by striker22

3 Likes

Using INT_MAX will overflow when you’re adding in line 24

1 Like

Yeah, I got the same problem.

Bro, If you add something to INT_MAX, it overflows the size of int and int+int=int, hence, due to overflow, it is giving error.

Okay, I got it.
Thank You.

So where do we use INT_MAX ?

When you have to just compare but not add to any other value which is of type int

INT_MAX is a macro defined to let you know what is the maximum value you can store in an 32-bit signed integer i.e. int.

You can use it here also or when you want to find min or max values in a sequence but you need to careful when you are doing any kind of arithmetic operations, better keep in mind that whenever you use INT_MAX, INT_MIN and doing some arithmetic operations, make sure that the variable in which you are storing the result must be of type long long int.