Segment
Time Limit: 2.0 s
Memory Limit: 256.0 MB
Description
You are provided with n segments, where each segment is represented by a pair of integers [l , r
], where l <= r. Your task is to construct an array A[] with exactly n elements by choosing one integer X from each segment such that:
All chosen integers are distinct.
The chosen integers are sorted in ascending order.
For each test case, determine if it's possible to construct such an array A[] and if so, output the array. Otherwise, print "NO".
Input
The first line contains a single integer t (1 ≤ t ≤ 5000)— the number of test cases.
For each test case:
The first line contains an integer n (1 ≤ n ≤ 2 × \(10^5\)) — the number of segments.
The next n lines each contain two integers l and r (1 ≤ l ≤ r ≤ \(10^9\))— the starting and the ending points of a segment
[l, r]
.
Sum of n overall test cases doesn't exceed \(2 * 10^5\)
Output
For each test case:
If a valid array A exists, print "YES" followed by n space-separated integers representing A. If there are
multiple
valid array A exist, you are allowed to print any of them.If it's not possible to construct such an array, print "NO"
Note : The output is
case insensitive
, meaning you may print "YES", "yes", "YeS", etc., and it will be considered correct.
Sample
Input | Output |
---|---|
|
|
Sample test case :
First test case:
we can select 1 from first segment, 2 from third segment and 3 from second segment.
Finay array A[]= {1,2,3}.
all integers unique and sorted in ascending order.
Second test case :
we can select 1 from second segment, 2 from first segment.
Final array A[]={1,2}.
Third test case:
It's impossible to construct such array.
Information
- ID
- 1185
- Difficulty
- 8
- Category
- Data_Structure | Math Click to Show
- Tags
- # Submissions
- 28
- Accepted
- 6
- Accepted Ratio
- 21%
- Uploaded By
Related
In following contests: