Codeforces Round 1077 (Div. 1)

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
2187 Codeforces Round 1077 (Div. 1) FINISHED False 10800 6708323 Jan. 29, 2026, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 15677 ) A Restricted Sorting PROGRAMMING binary search constructive algorithms greedy sortings

You are given an array (a) of length (n). For an integer (k), we call it piggy if and only if it is possible to sort (a) in non-descending order by performing the following operation an arbitrary number of times (possibly zero): First, select two indices (i) and (j) ((1 \le i < j \le n)) such that (|a_i - a_j| \ge k); Then, swap (a_i) and (a_j). You need to determine the largest piggy integer (k). If such an integer does not exist, output (-1). 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 \le n \le 2 \cdot 10^5)) — the length of (a). The second line contains (n) integers (a_1,a_2,\ldots,a_n) ((1 \le a_i \le 10^9)) — the elements of (a). It is guaranteed that the sum of (n) over all test cases does not exceed (2\cdot10^5). For each test case, output a single integer — the largest piggy integer (k). If such an integer does not exist, output (-1) instead. In the first and the second test case, no matter how large (k) is, you can always sort (a) in non-descending order by not performing any operations. In the third test case, the largest piggy (k) is (2). We can select (i=2) and (j=3) in the first operation, since (|a_2-a_3|=|4-2|=2 \ge k), and (a) is sorted in non-descending order. It can be proven that no piggy integers larger than (2) exist.

Tutorials

Codeforces Round 1077 (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
360501233 niwrad A Jan. 29, 2026, 2:48 p.m. OK C++17 (GCC 7-32) TESTS 15 62 0
360666147 ritvij611 A Jan. 30, 2026, 5:32 a.m. OK C++17 (GCC 7-32) TESTS 15 78 0
360659962 dkedu A Jan. 30, 2026, 4:32 a.m. OK C++17 (GCC 7-32) TESTS 15 78 0
360656991 Nullsafe A Jan. 30, 2026, 3:50 a.m. OK C++17 (GCC 7-32) TESTS 15 78 0
360656206 Nullsafe A Jan. 30, 2026, 3:36 a.m. OK C++17 (GCC 7-32) TESTS 15 78 0
360655857 Crocubott01 A Jan. 30, 2026, 3:30 a.m. OK C++17 (GCC 7-32) TESTS 15 78 0
360640611 Midcoldnight A Jan. 29, 2026, 9:40 p.m. OK C++17 (GCC 7-32) TESTS 15 78 0
360639776 prabhakar.07.07.07 A Jan. 29, 2026, 9:26 p.m. OK C++17 (GCC 7-32) TESTS 15 78 0
360622985 Anubhav_Maheshwari A Jan. 29, 2026, 6:33 p.m. OK C++17 (GCC 7-32) TESTS 15 78 0
360509901 OkClinty A Jan. 29, 2026, 2:55 p.m. OK C++17 (GCC 7-32) TESTS 15 78 0
360565812 Pigsyy1024 A Jan. 29, 2026, 3:53 p.m. OK C++20 (GCC 13-64) TESTS 15 62 0
360533249 FelixMP A Jan. 29, 2026, 3:15 p.m. OK C++20 (GCC 13-64) TESTS 15 62 0
360524799 BinarCat A Jan. 29, 2026, 3:07 p.m. OK C++20 (GCC 13-64) TESTS 15 62 0
360495268 rhineofts A Jan. 29, 2026, 2:43 p.m. OK C++20 (GCC 13-64) TESTS 15 62 0
360667602 Alasco A Jan. 30, 2026, 5:44 a.m. OK C++20 (GCC 13-64) TESTS 15 62 102400
360493113 Rodger2041 A Jan. 29, 2026, 2:42 p.m. OK C++20 (GCC 13-64) TESTS 15 62 921600
360646549 seanlsy A Jan. 29, 2026, 11:46 p.m. OK C++20 (GCC 13-64) TESTS 15 62 1638400
360496828 NeverLand A Jan. 29, 2026, 2:45 p.m. OK C++20 (GCC 13-64) TESTS 15 62 1638400
360495512 AshenWitch A Jan. 29, 2026, 2:44 p.m. OK C++20 (GCC 13-64) TESTS 15 62 1638400
360496645 www_bilibili_com A Jan. 29, 2026, 2:44 p.m. OK C++20 (GCC 13-64) TESTS 15 62 1740800
360650821 siddharth8052 A Jan. 30, 2026, 1:51 a.m. OK C++23 (GCC 14-64, msys2) TESTS 15 62 0
360650507 Lucifer_fallen A Jan. 30, 2026, 1:44 a.m. OK C++23 (GCC 14-64, msys2) TESTS 15 62 0
360621213 lnsuyn A Jan. 29, 2026, 6:22 p.m. OK C++23 (GCC 14-64, msys2) TESTS 15 62 0
360526477 ch1ll_guy A Jan. 29, 2026, 3:09 p.m. OK C++23 (GCC 14-64, msys2) TESTS 15 62 0
360525888 alzahrawi A Jan. 29, 2026, 3:08 p.m. OK C++23 (GCC 14-64, msys2) TESTS 15 62 0
360516689 Yousef.Osama A Jan. 29, 2026, 3 p.m. OK C++23 (GCC 14-64, msys2) TESTS 15 62 0
360502928 JYJin A Jan. 29, 2026, 2:49 p.m. OK C++23 (GCC 14-64, msys2) TESTS 15 62 0
360501774 JahonaliX A Jan. 29, 2026, 2:48 p.m. OK C++23 (GCC 14-64, msys2) TESTS 15 62 0
360500159 zyadhany A Jan. 29, 2026, 2:47 p.m. OK C++23 (GCC 14-64, msys2) TESTS 15 62 0
360495255 HIR180 A Jan. 29, 2026, 2:43 p.m. OK C++23 (GCC 14-64, msys2) TESTS 15 62 0
360514278 hos.lyric A Jan. 29, 2026, 2:58 p.m. OK D TESTS 15 265 27443200
360526221 pengin_2000 A Jan. 29, 2026, 3:09 p.m. OK GNU C11 TESTS 15 78 2355200
360570533 Ritwin A Jan. 29, 2026, 3:59 p.m. OK GNU C11 TESTS 15 93 1638400
360641724 Cessdav A Jan. 29, 2026, 9:59 p.m. OK GNU C11 TESTS 15 93 4915200
360655462 Huhh_ A Jan. 30, 2026, 3:23 a.m. OK Go TESTS 15 46 10547200
360655203 Huhh_ A Jan. 30, 2026, 3:19 a.m. OK Go TESTS 15 62 10444800
360510853 Hmzaawy A Jan. 29, 2026, 2:56 p.m. OK Go TESTS 15 78 4300800
360587554 MBBN A Jan. 29, 2026, 4:27 p.m. OK Java 21 TESTS 15 218 1945600
360652900 sathwikhbhat A Jan. 30, 2026, 2:37 a.m. OK Java 21 TESTS 15 296 2867200
360651955 thamizhvendhan A Jan. 30, 2026, 2:17 a.m. OK Java 21 TESTS 15 578 1228800
360636609 f20212826g A Jan. 29, 2026, 8:40 p.m. OK Java 21 TESTS 15 671 2355200
360498062 Goku_Kakarot A Jan. 29, 2026, 2:45 p.m. OK Java 8 TESTS 15 187 3788800
360558177 NeelmaniPandey09 A Jan. 29, 2026, 3:43 p.m. OK Java 8 TESTS 15 328 5324800
360655327 Vishalll_ A Jan. 30, 2026, 3:21 a.m. OK Java 8 TESTS 15 406 0
360490932 Tlatoani A Jan. 29, 2026, 2:40 p.m. OK Kotlin 2.2 TESTS 15 312 26624000
360630645 Ne_xt_ A Jan. 29, 2026, 7:37 p.m. OK PyPy 3 TESTS 15 437 18534400
360503916 teekaytai A Jan. 29, 2026, 2:50 p.m. OK PyPy 3-64 TESTS 15 140 21606400
360519210 meow_love A Jan. 29, 2026, 3:02 p.m. OK PyPy 3-64 TESTS 15 156 27033600
360511742 gs25010 A Jan. 29, 2026, 2:56 p.m. OK PyPy 3-64 TESTS 15 156 27136000
360500245 34z12000 A Jan. 29, 2026, 2:47 p.m. OK PyPy 3-64 TESTS 15 156 27136000
360491453 Ergodic137 A Jan. 29, 2026, 2:40 p.m. OK PyPy 3-64 TESTS 15 156 27238400
360489700 harurun4635 A Jan. 29, 2026, 2:39 p.m. OK PyPy 3-64 TESTS 15 171 20787200
360498165 kdy8128 A Jan. 29, 2026, 2:46 p.m. OK PyPy 3-64 TESTS 15 171 27136000
360492857 smilences A Jan. 29, 2026, 2:42 p.m. OK PyPy 3-64 TESTS 15 171 27136000
360532039 sshs22002 A Jan. 29, 2026, 3:14 p.m. OK PyPy 3-64 TESTS 15 171 27238400
360498367 sav A Jan. 29, 2026, 2:46 p.m. OK PyPy 3-64 TESTS 15 171 27238400
360498401 shade34 A Jan. 29, 2026, 2:46 p.m. OK Python 3 TESTS 15 250 26624000
360669871 wenki A Jan. 30, 2026, 6:03 a.m. OK Python 3 TESTS 15 265 26726400
360497654 devparth_7 A Jan. 29, 2026, 2:45 p.m. OK Python 3 TESTS 15 281 26726400
360507658 Egor A Jan. 29, 2026, 2:53 p.m. OK Rust 2024 TESTS 15 46 11776000
360496376 Mon_ster A Jan. 29, 2026, 2:44 p.m. OK Rust 2024 TESTS 15 46 15564800
360504208 drydock A Jan. 29, 2026, 2:50 p.m. OK Rust 2024 TESTS 15 62 11980800
360506705 darkkcyan A Jan. 29, 2026, 2:52 p.m. OK Rust 2024 TESTS 15 78 9830400
360498452 Darknef A Jan. 29, 2026, 2:46 p.m. OK Rust 2024 TESTS 15 78 14131200

remove filters

Back to search problems