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.
ContestId |
Name |
Phase |
Frozen |
Duration (Seconds) |
Relative Time |
Start Time |
1566
|
Codeforces Global Round 16 |
FINISHED |
False |
9000 |
105722662 |
Sept. 12, 2021, 2:35 p.m. |
Problems
B"There are n points and m segments on the coordinate line. The initial coordinate of the i -th point is a_i . The endpoints of the j -th segment are l_j and r_j -- left and right endpoints, respectively. You can move the points. In one move you can move any point from its current coordinate x to the coordinate x - 1 or the coordinate x + 1 . The cost of this move is 1 . You should move the points in such a way that each segment is visited by at least one point. A point visits the segment [l, r] if there is a moment when its coordinate was on the segment [l, r] (including endpoints). You should find the minimal possible total cost of all moves such that all segments are visited. The input consists of multiple test cases. The first line contains a single integer t ( 1 <= t <= 10^4 ) -- the number of test cases. Description of the test cases follows. The first line of each test case contains two integers n and m ( 1 <= n, m <= 2 cdot 10^5 ) -- the number of points and segments respectively. The next line contains n distinct integers a_1, a_2, ldots, a_n ( -10^9 <= a_i <= 10^9 ) -- the initial coordinates of the points. Each of the next m lines contains two integers l_j , r_j ( -10^9 <= l_j <= r_j <= 10^9 ) -- the left and the right endpoints of the j -th segment. It's guaranteed that the sum of n and the sum of m over all test cases does not exceed 2 cdot 10^5 . For each test case print a single integer -- the minimal total cost of all moves such that all segments are visited. In the first test case the points can be moved as follows: The total cost of moves is 5 . It is easy to see, that all segments are visited by these movements. For example, the tenth segment ( [7, 13] ) is visited after the second move by the third point. Here is the image that describes the first tes"... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
128675705 |
azukun |
F |
Sept. 12, 2021, 8:38 p.m. |
OK |
.NET Core C# |
TESTS |
29 |
373 |
44236800 |
|
|
128659349 |
Yupiteru |
F |
Sept. 12, 2021, 4:53 p.m. |
OK |
.NET Core C# |
TESTS |
29 |
1029 |
114073600 |
|
|
remove filters
Back to search problems