##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
3
3 1 3 2 4 3 5
3 5 7 1 3 2 4
4 2 4 1 3 5 7 1 2
1 2 3
2 3 1
1 2 4 3
You are given closed intervals .
You want to choose a permutation of such that there exists an array satisfying:
Among all permutations for which such an array exists, output the lexicographically smallest permutation.
It is guaranteed that at least one valid permutation exists.
Scenario 1: , intervals . Answer: . Witness: . Reading in permutation order: . All values in range. The identity permutation works because the intervals already overlap in increasing order. All permutations are valid (intervals overlap heavily), but is lexicographically smallest.
Scenario 2: , intervals . Answer: . Witness: . Reading in permutation order: . Interval has high values while intervals have low values, so index must come last. Only valid permutations exist: and . Lexicographically smallest is .
Scenario 3: , intervals . Answer: . Witness: . Reading in permutation order: . Interval has high values so must come last. Among the remaining, index fits before . There are valid permutations; is lexicographically smallest.