#B3906. Overflow Possibility in Integer Multiplication
Overflow Possibility in Integer Multiplication
Overflow Possibility in Integer Multiplication
Analyzing the data range is crucial in programming contests. In this problem, you are given two int
type variables x and y along with their respective ranges. You need to determine whether the product x \times y could possibly exceed the range representable by a 32-bit int
.
The int
type has a range of \( [-2147483648,\;2147483647] \) which can also be written as \( [-2^{31},\;2^{31}-1] \). That is, the minimum value is \(-2147483648\) and the maximum value is \(2147483647\).
You are given four integers: the minimum and maximum values for x and the minimum and maximum values for y. Determine if there exists a pair \((x, y)\) from the given ranges such that the product x \times y is strictly less than \(-2147483648\) or strictly greater than \(2147483647\). If so, output YES, otherwise output NO.
inputFormat
The input consists of a single line containing four space-separated integers:
- x_min - the minimum possible value of x
- x_max - the maximum possible value of x
- y_min - the minimum possible value of y
- y_max - the maximum possible value of y
outputFormat
Output a single line containing YES if it is possible for the product x \times y to fall outside the range of a 32-bit int
\( [-2^{31},\;2^{31}-1] \). Otherwise, output NO.
sample
1 10 1 10
NO