#5450. Problem 3. Min Max Subarrays II
Problem 3. Min Max Subarrays II
Problem 3. Min Max Subarrays II
USACO 2026 Third Contest, Platinum
You are given integers and constraints represented by four integers $(1 \leq t_i \leq 2, 1 \leq l_i \leq r_i \leq N, 0 \leq k_i \leq 10^9,$ all are distinct
Construct an array consisting of integers between and such that for all , if and if . If multiple valid arrays exist, print any. If no valid array exists, print .
INPUT FORMAT (input arrives from the terminal / stdin):
The first line contains an integer () representing the number of independent test cases.
For each test case, the first line contains two integers .
The next lines each contain 4 integers .
It is guaranteed that neither the sum of nor the sum of over all test cases exceed .
OUTPUT FORMAT (print output to the terminal / stdout):
For each test case, if a valid array exists, output space-separated integers on a new line. Otherwise, print .
SAMPLE INPUT:
3 2 2 1 1 2 1 1 1 2 2 2 2 1 1 2 1 1 2 2 2 4 1 2 2 4 3
SAMPLE OUTPUT:
-1 1 2 0 3 0 0
In the first test case, the answer is because the minimum value of the array cannot be both and at the same time.
In the second test case, has a minimum of at in the sample output, satisfying the first constraint. Since , the second constraint is also satisfied.
In the third test case, there are multiple solutions. For instance, the array would also be accepted.
SAMPLE INPUT:
4 2 2 1 1 2 1 2 1 2 2 3 2 1 1 2 3 2 2 3 1 5 2 1 1 2 3 1 4 5 2 4 4 1 1 4 1 1 2 3 2 2 1 2 5 2 3 4 6
SAMPLE OUTPUT:
1 2 -1 3 3 0 2 2 1 5 2 6
In the second test case, the array satisfies the first constraint but not the second constraint. Contrarily, the array satisfies the second constraint but not the first constraint. It can be proven that no array can satisfy both constraints at the same time, hence the answer is .
For all other test cases, it can be proven that the constructed array satisfies all constraints.
SCORING: Inputs 3-4: and all within the same test case are equalInputs 5-6: all within the same test case are equalInputs 7-10: Inputs 11-14: No additional constraints.
Problem credits: Charlie Yang