Segment
You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.
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.
Brain Booster #9
- Status
- Done
- Rule
- ACM/ICPC
- Problem
- 9
- Start at
- 2025-04-06 15:30
- End at
- 2025-04-06 18:00
- Duration
- 2.5 hour(s)
- Host
- Partic.
- 90