Solutions are presented as using the least memory and the fastest execution time. It also takes the top
10 most recent solutions from each language. If you want to limit to a specific index, click the
"Solved" button and go to that problem.
Problems
B'You are given a set of n segments on a line [L_i; R_i] . All 2n segment endpoints are pairwise distinct integers. The set is laminar -- any two segments are either disjoint or one of them contains the other. Choose a non-empty subsegment [l_i, r_i] with integer endpoints in each segment ( L_i <= l_i < r_i <= R_i ) in such a way that no two subsegments intersect (they are allowed to have common endpoints though) and the sum of their lengths ( sum_{i=1}^n r_i - l_i ) is maximized. The first line contains a single integer n ( 1 <= n <= 2 cdot 10^3 ) -- the number of segments. The i -th of the next n lines contains two integers L_i and R_i ( 0 <= L_i < R_i <= 10^9 ) -- the endpoints of the i -th segment. All the given 2n segment endpoints are distinct. The set of segments is laminar. On the first line, output the maximum possible sum of subsegment lengths. On the i -th of the next n lines, output two integers l_i and r_i ( L_i <= l_i < r_i <= R_i ), denoting the chosen subsegment of the i -th segment. The example input and the example output are illustrated below. '... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
112037109 |
scott_wu ecnerwala ksun48 |
H |
April 4, 2021, 11:38 p.m. |
OK |
GNU C++17 (64) |
TESTS |
132 |
62 |
87347200 |
|
|
112003114 |
Um_nik KAN Merkurev |
H |
April 4, 2021, 12:54 p.m. |
OK |
GNU C++17 (64) |
TESTS |
132 |
187 |
262451200 |
|
|
remove filters
Back to search problems