#P6123. Simplify Linear Constraints
Simplify Linear Constraints
Simplify Linear Constraints
You are given a single variable x and a set of constraints in the form of $x \geq a$ or $x \leq a$, where a is an integer. The constraints are separated by ||
. Your task is to simplify these constraints by combining them into a single, equivalent constraint.
For the simplification, consider the following:
- For all constraints of the form $x \geq a$, choose the maximum a as the effective lower bound.
- For all constraints of the form $x \leq a$, choose the minimum a as the effective upper bound.
- If both a lower bound and an upper bound exist and the lower bound is greater than the upper bound, then the constraints are contradictory; output
false
. - If only one type of constraint is present, output that constraint alone.
- If both are valid, output the simplified constraint in the form
x >= L and x <= U
whereL
andU
are the simplified bounds.
inputFormat
The input consists of a single line containing one or more constraints separated by ||
. Each constraint is in one of the following LaTeX formats:
$x \geq a$ or $x \leq a$, where a is an integer.
outputFormat
Output the simplified constraint. The output should be one of the following formats:
- If both lower and upper bounds are applicable and valid, output:
x >= L and x <= U
- If only a lower bound is provided, output:
x >= L
- If only an upper bound is provided, output:
x <= U
- If the constraints are contradictory, output:
false
sample
x >= 3||x <= 7
x >= 3 and x <= 7