Codeforces Round 884 (Div. 1 + 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
1844 Codeforces Round 884 (Div. 1 + Div. 2) FINISHED False 10800 48093863 July 11, 2023, 2:35 p.m.

Problems

Solved$
Index
Name
Type
Tags
Community Tag
Rating
( 407 ) F2 Min Cost Permutation (Hard Version) PROGRAMMING binary search data structures graphs greedy sortings

B'The only difference between this problem and the easy version is the constraints on t and n . You are given an array of n positive integers a_1, ... ,a_n , and a (possibly negative) integer c . Across all permutations b_1, ... ,b_n of the array a_1, ... ,a_n , consider the minimum possible value of sum_{i=1}^{n-1} |b_{i+1}-b_i-c|. Find the lexicographically smallest permutation b of the array a that achieves this minimum. A sequence x is lexicographically smaller than a sequence y if and only if one of the following holds: Each test contains multiple test cases. The first line contains the number of test cases t ( 1 <= t <= 10^4 ). The description of the test cases follows. The first line of each test case contains two integers n and c ( 1 <= n <= 2 cdot 10^5 , -10^9 <= c <= 10^9 ). The second line of each test case contains n integers a_1, ... ,a_n ( 1 <= a_i <= 10^9 ). It is guaranteed that the sum of n over all test cases does not exceed 2 cdot 10^5 . For each test case, output n integers b_1, ... ,b_n , the lexicographically smallest permutation of a that achieves the minimum sum limits_{i=1}^{n-1} |b_{i+1}-b_i-c| . In the first test case, it can be proven that the minimum possible value of sum limits_{i=1}^{n-1} |b_{i+1}-b_i-c| is 27 , and the permutation b = [9,3,1,4,5,1] is the lexicographically smallest permutation of a that achieves this minimum: |3-9-(-7)|+|1-3-(-7)|+|4-1-(-7)|+|5-4-(-7)|+|1-5-(-7)| = 1+5+10+8+3 = 27 . In the second test case, the minimum possible value of sum limits_{i=1}^{n-1} |b_{i+1}-b_i-c| is 0 , and b = [1,3,5] is the lexicographically smallest permutation of a that achieves this. In the third test case, there is only one permutation b . '...

Tutorials

Codeforces Round #884 (Div. 1 + Div. 2) Editorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
213430146 rainboy F2 July 11, 2023, 11:22 p.m. OK GNU C11 TESTS 27 1232 7987200
213394627 0wuming0 F2 July 11, 2023, 5:10 p.m. OK GNU C++14 TESTS 26 202 9011200
213455271 cyh_toby F2 July 12, 2023, 5:35 a.m. OK GNU C++14 TESTS 28 202 9830400
213442352 huzhaoyang F2 July 12, 2023, 2:24 a.m. OK GNU C++14 TESTS 28 218 9011200
213405405 fanchy100 F2 July 11, 2023, 6:08 p.m. OK GNU C++14 TESTS 26 233 14950400
213400676 Scintilla06 F2 July 11, 2023, 5:30 p.m. OK GNU C++14 TESTS 26 2308 10035200
213426812 Unlimited_zero F2 July 11, 2023, 10:11 p.m. OK GNU C++17 TESTS 27 155 6451200
213408413 KroosTheKeenGlint F2 July 11, 2023, 6:27 p.m. OK GNU C++17 TESTS 26 156 9523200
213410061 Jhuni F2 July 11, 2023, 6:39 p.m. OK GNU C++17 TESTS 26 187 13619200
213397329 Morphymorphymorphy F2 July 11, 2023, 5:19 p.m. OK GNU C++17 TESTS 26 202 5324800
213399348 plast F2 July 11, 2023, 5:25 p.m. OK GNU C++17 TESTS 26 202 14336000
213400346 tokusakurai F2 July 11, 2023, 5:29 p.m. OK GNU C++17 TESTS 26 202 15462400
213442365 KaphI F2 July 12, 2023, 2:24 a.m. OK GNU C++17 TESTS 28 217 22630400
213417797 ATM12345 F2 July 11, 2023, 8 p.m. OK GNU C++17 TESTS 26 218 29081600
213399850 Alon-Tanay F2 July 11, 2023, 5:27 p.m. OK GNU C++17 TESTS 26 264 16281600
213421507 abhishek6487209 F2 July 11, 2023, 8:44 p.m. OK GNU C++17 TESTS 26 296 19558400
213418391 neal F2 July 11, 2023, 8:07 p.m. OK GNU C++17 (64) TESTS 26 140 14745600
213446420 MIKEFENG F2 July 12, 2023, 3:14 a.m. OK GNU C++17 (64) TESTS 28 171 20377600
213453809 zihouzhong F2 July 12, 2023, 5:11 a.m. OK GNU C++17 (64) TESTS 28 186 22323200
213411369 Kude F2 July 11, 2023, 6:50 p.m. OK GNU C++17 (64) TESTS 26 186 22323200
213398779 kotatsugame F2 July 11, 2023, 5:23 p.m. OK GNU C++17 (64) TESTS 26 187 20992000
213401727 244mhq F2 July 11, 2023, 5:33 p.m. OK GNU C++17 (64) TESTS 26 187 34816000
213397774 Nextby F2 July 11, 2023, 5:20 p.m. OK GNU C++17 (64) TESTS 26 202 13619200
213408501 trainwithoutpain F2 July 11, 2023, 6:27 p.m. OK GNU C++17 (64) TESTS 26 202 14438400
213417990 MAOooOAM F2 July 11, 2023, 8:02 p.m. OK GNU C++17 (64) TESTS 26 217 12083200
213393647 LXH-cat F2 July 11, 2023, 5:06 p.m. OK GNU C++17 (64) TESTS 26 217 20992000
213402111 joww F2 July 11, 2023, 5:34 p.m. OK GNU C++20 (64) TESTS 26 77 3993600
213405626 memset0c F2 July 11, 2023, 6:09 p.m. OK GNU C++20 (64) TESTS 26 78 3788800
213405242 joww F2 July 11, 2023, 6:08 p.m. OK GNU C++20 (64) TESTS 26 78 3993600
213398053 gisp_zjz F2 July 11, 2023, 5:21 p.m. OK GNU C++20 (64) TESTS 26 78 15155200
213394774 Timelpn F2 July 11, 2023, 5:10 p.m. OK GNU C++20 (64) TESTS 26 93 3788800
213407040 memset0c F2 July 11, 2023, 6:18 p.m. OK GNU C++20 (64) TESTS 26 109 3788800
213407502 maxplus F2 July 11, 2023, 6:20 p.m. OK GNU C++20 (64) TESTS 26 109 10444800
213418756 Arnab_11 F2 July 11, 2023, 8:11 p.m. OK GNU C++20 (64) TESTS 26 109 18329600
213402510 tatyam F2 July 11, 2023, 5:34 p.m. OK GNU C++20 (64) TESTS 26 109 19251200
213410374 feeder1 F2 July 11, 2023, 6:42 p.m. OK GNU C++20 (64) TESTS 26 124 21196800
213437993 dzhi F2 July 12, 2023, 1:31 a.m. OK Java 11 TESTS 28 561 35942400
213438871 dzhi F2 July 12, 2023, 1:42 a.m. OK Java 11 TESTS 28 576 35942400

remove filters

Back to search problems