Codeforces Round 1049 (Div. 2)

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
2140 Codeforces Round 1049 (Div. 2) FINISHED False 7200 18977123 Sept. 9, 2025, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 4861 ) D A Cruel Segment's Thesis PROGRAMMING greedy math sortings

You are given (n) segments on a number line. The (i)-th segment is represented as (l_i, r_i). Initially, all the segments are unmarked . You perform the following operation repeatedly until there are no unmarked segments left: In the (k)-th operation, if there are at least two unmarked segments, choose any two unmarked segments (l_i, r_i) and (l_j, r_j), mark both of them , and add a new marked segment (x_k, y_k) satisfying the following conditions: (l_i \leq x_k \leq r_i), (l_j \leq y_k \leq r_j), (x_k \leq y_k). (l_i \leq x_k \leq r_i), (l_j \leq y_k \leq r_j), (x_k \leq y_k). If there is exactly one unmarked segment remaining, mark it . Your task is to determine the maximum possible sum of lengths of all the marked segments at the end of the process. Note that the length of a segment ((l,r)) is (r-l). Each test contains multiple test cases. The first line contains the number of test cases (t) ((1 \le t \le 10^4)). The description of the test cases follows. The first line of each test case contains a single integer (n) ((1 \leq n \leq 2 \cdot 10^5)) — the number of segments. Each of the next (n) lines contains two integers (l_i) and (r_i) ((1 \leq l_i \leq r_i \leq 10^9)) — the (i)-th segment. It is guaranteed that the sum of (n) across all test cases does not exceed (2 \cdot 10^5). For each test case, print a single integer — the maximum possible total length of all marked segments at the end of the process. In the first test case, we choose the given two segments and make the new segment (1, 10^9). In the second test case, we choose the segments (1, 10) and (2, 15) and make the new segment (1,15). Now, (3, 9) is the only segment that is left unmarked, and it will be marked in the next step.

Tutorials

Codeforces Round 1049 (Div. 2) Editorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
337857721 og.kostya D Sept. 9, 2025, 5:55 p.m. OK C# 10 TESTS 20 140 2867200
337857762 og.kostya D Sept. 9, 2025, 5:55 p.m. OK C# 13 TESTS 20 171 3072000
337894648 I_like_magic D Sept. 10, 2025, 3:57 a.m. OK C# 13 TESTS 20 265 21196800
337875350 Phantom_Dreams D Sept. 9, 2025, 9:32 p.m. OK C++17 (GCC 7-32) TESTS 20 125 3276800
337900149 Geoyster D Sept. 10, 2025, 5:14 a.m. OK C++17 (GCC 7-32) TESTS 20 140 0
337890331 lyrrr D Sept. 10, 2025, 2:50 a.m. OK C++17 (GCC 7-32) TESTS 20 140 1638400
337839043 edwardblue D Sept. 9, 2025, 4:16 p.m. OK C++17 (GCC 7-32) TESTS 20 140 3276800
337893552 zwb2_2 D Sept. 10, 2025, 3:41 a.m. OK C++17 (GCC 7-32) TESTS 20 140 4812800
337895070 wuyin331 D Sept. 10, 2025, 4:03 a.m. OK C++17 (GCC 7-32) TESTS 20 140 5017600
337903790 TheForsaking D Sept. 10, 2025, 5:57 a.m. OK C++17 (GCC 7-32) TESTS 20 140 56115200
337871754 roygaurav2004 D Sept. 9, 2025, 8:26 p.m. OK C++17 (GCC 7-32) TESTS 20 155 0
337850209 liangzexian D Sept. 9, 2025, 5:03 p.m. OK C++17 (GCC 7-32) TESTS 20 155 0
337903105 000123 D Sept. 10, 2025, 5:49 a.m. OK C++17 (GCC 7-32) TESTS 20 155 921600
337903574 _Kee D Sept. 10, 2025, 5:54 a.m. OK C++20 (GCC 13-64) TESTS 20 78 0
337900435 jinyq D Sept. 10, 2025, 5:17 a.m. OK C++20 (GCC 13-64) TESTS 20 92 26521600
337882195 Redial D Sept. 10, 2025, 12:08 a.m. OK C++20 (GCC 13-64) TESTS 20 109 2457600
337899141 heiguodong D Sept. 10, 2025, 5 a.m. OK C++20 (GCC 13-64) TESTS 20 124 0
337876113 GusFring D Sept. 9, 2025, 9:51 p.m. OK C++20 (GCC 13-64) TESTS 20 124 0
337858495 xiapali D Sept. 9, 2025, 6:01 p.m. OK C++20 (GCC 13-64) TESTS 20 124 0
337850744 Spirit D Sept. 9, 2025, 5:04 p.m. OK C++20 (GCC 13-64) TESTS 20 124 0
337850342 Maaaaa D Sept. 9, 2025, 5:03 p.m. OK C++20 (GCC 13-64) TESTS 20 124 0
337843694 Istahak16 D Sept. 9, 2025, 4:26 p.m. OK C++20 (GCC 13-64) TESTS 20 124 0
337885265 JustA7 D Sept. 10, 2025, 1:19 a.m. OK C++20 (GCC 13-64) TESTS 20 124 102400
337886801 424479543 D Sept. 10, 2025, 1:48 a.m. OK C++23 (GCC 14-64, msys2) TESTS 20 93 102400
337902762 sahil_beck D Sept. 10, 2025, 5:46 a.m. OK C++23 (GCC 14-64, msys2) TESTS 20 124 0
337898678 ArrogHie D Sept. 10, 2025, 4:54 a.m. OK C++23 (GCC 14-64, msys2) TESTS 20 124 0
337896209 xixilwz D Sept. 10, 2025, 4:20 a.m. OK C++23 (GCC 14-64, msys2) TESTS 20 124 0
337889047 rns_pis1 D Sept. 10, 2025, 2:27 a.m. OK C++23 (GCC 14-64, msys2) TESTS 20 124 0
337886829 Incredible0306 D Sept. 10, 2025, 1:48 a.m. OK C++23 (GCC 14-64, msys2) TESTS 20 124 0
337882307 Citypop D Sept. 10, 2025, 12:10 a.m. OK C++23 (GCC 14-64, msys2) TESTS 20 124 0
337881607 Yuichiro17 D Sept. 9, 2025, 11:56 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 124 0
337900729 xinhuo D Sept. 10, 2025, 5:21 a.m. OK C++23 (GCC 14-64, msys2) TESTS 20 124 102400
337898911 zerc_7 D Sept. 10, 2025, 4:57 a.m. OK C++23 (GCC 14-64, msys2) TESTS 20 124 102400
337841313 k.saijaswanth D Sept. 9, 2025, 4:21 p.m. OK Go TESTS 20 467 14745600
337850869 lyongwolf D Sept. 9, 2025, 5:06 p.m. OK Java 21 TESTS 20 358 1433600
337844407 SumitXorY D Sept. 9, 2025, 4:28 p.m. OK Java 21 TESTS 20 390 7782400
337839844 NpHardcore_05 D Sept. 9, 2025, 4:18 p.m. OK Java 21 TESTS 20 467 15974400
337842834 nabina1395 D Sept. 9, 2025, 4:24 p.m. OK Java 21 TESTS 20 468 716800
337838996 bikashkumarkundu99 D Sept. 9, 2025, 4:16 p.m. OK Java 21 TESTS 20 515 18329600
337839408 iamalizaidi D Sept. 9, 2025, 4:17 p.m. OK Java 21 TESTS 20 546 5939200
337864038 MaxBuzz D Sept. 9, 2025, 6:52 p.m. OK Java 21 TESTS 20 546 6041600
337844925 Pikaboo_2609 D Sept. 9, 2025, 4:29 p.m. OK Java 21 TESTS 20 546 9420800
337859998 Freankin D Sept. 9, 2025, 6:14 p.m. OK Java 21 TESTS 20 561 13004800
337845500 leelaprasad2004 D Sept. 9, 2025, 4:30 p.m. OK Java 21 TESTS 20 562 6758400
337838806 amber_100 D Sept. 9, 2025, 4:16 p.m. OK Java 8 TESTS 20 421 9011200
337861518 kasiru_69 D Sept. 9, 2025, 6:27 p.m. OK Java 8 TESTS 20 483 18636800
337838459 NeelmaniPandey09 D Sept. 9, 2025, 4:15 p.m. OK Java 8 TESTS 20 499 16281600
337852223 LALALULU00 D Sept. 9, 2025, 5:13 p.m. OK Java 8 TESTS 20 515 16588800
337865992 saiashish9 D Sept. 9, 2025, 7:12 p.m. OK Java 8 TESTS 20 874 7680000
337866111 saiashish9 D Sept. 9, 2025, 7:13 p.m. OK Java 8 TESTS 20 890 7782400
337846276 chinesedfan D Sept. 9, 2025, 4:31 p.m. OK Node.js TESTS 20 562 49971200
337843073 AL_Qiswa D Sept. 9, 2025, 4:25 p.m. OK PyPy 3 TESTS 20 1483 38400000
337840687 makimakimakki D Sept. 9, 2025, 4:20 p.m. OK PyPy 3 TESTS 20 1858 21708800
337877688 denilb D Sept. 9, 2025, 10:30 p.m. OK PyPy 3-64 TESTS 20 405 26112000
337877502 denilb D Sept. 9, 2025, 10:27 p.m. OK PyPy 3-64 TESTS 20 421 29696000
337855687 MinValgen D Sept. 9, 2025, 5:38 p.m. OK PyPy 3-64 TESTS 20 499 30822400
337890234 Little_Sheep_Yawn D Sept. 10, 2025, 2:48 a.m. OK PyPy 3-64 TESTS 20 514 28672000
337838178 mkawa2 D Sept. 9, 2025, 4:14 p.m. OK PyPy 3-64 TESTS 20 531 29491200
337847946 elioing D Sept. 9, 2025, 4:34 p.m. OK PyPy 3-64 TESTS 20 562 20992000
337845755 _curnxt D Sept. 9, 2025, 4:30 p.m. OK PyPy 3-64 TESTS 20 624 16179200
337848392 SubArU_76 D Sept. 9, 2025, 4:34 p.m. OK PyPy 3-64 TESTS 20 624 55398400
337871053 czjnbb D Sept. 9, 2025, 8:15 p.m. OK PyPy 3-64 TESTS 20 718 23654400
337867847 temporary D Sept. 9, 2025, 7:33 p.m. OK PyPy 3-64 TESTS 20 749 26419200
337860768 Ig_light D Sept. 9, 2025, 6:20 p.m. OK Python 3 TESTS 20 592 50892800
337842484 Easy_AC D Sept. 9, 2025, 4:24 p.m. OK Python 3 TESTS 20 624 92467200
337879386 MDelPiero D Sept. 9, 2025, 11:03 p.m. OK Python 3 TESTS 20 656 73625600
337846541 WickedLordShingan D Sept. 9, 2025, 4:32 p.m. OK Python 3 TESTS 20 718 69120000
337839739 speedcuberayush D Sept. 9, 2025, 4:18 p.m. OK Python 3 TESTS 20 734 61747200
337838597 r-tron18 D Sept. 9, 2025, 4:15 p.m. OK Python 3 TESTS 20 780 65331200
337844828 lyteabovenyte D Sept. 9, 2025, 4:29 p.m. OK Rust 2021 TESTS 20 77 10956800
337857934 vmhung D Sept. 9, 2025, 5:56 p.m. OK Rust 2024 TESTS 20 77 4505600

remove filters

Back to search problems