Weird overflow behavior of min(a,b) function

Правка en2, от lvisbl_, 2024-10-15 13:16:22

Recently I have done 711C - Coloring Trees, and I have found an overflow when I use min(a,b) function. More specifically, if I use:

min(a, b + c) when a, b and c are long long and sum of b + c large than 32-bit integer then the sum b + c will be treated as 32-bits integer and hence the overflow.

but let say, if I use a temporary variable:

long long tmp = b + c

then

min(a, tmp) will not overflow

What kind of behavior is this?

This is two submissions, one is overflow and the another one use a temporary variable will not overflow:

Overflow: 285989412

Not overflow: 286024512

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский lvisbl_ 2024-10-15 13:16:22 16
en1 Английский lvisbl_ 2024-10-15 13:15:24 655 Initial revision (published)