Codeforces Round 1019 (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
2103 Codeforces Round 1019 (Div. 2) FINISHED False 7200 31159523 April 21, 2025, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 597 ) E Keep the Sum PROGRAMMING constructive algorithms data structures

You are given an integer (k) and an array (a) of length (n), where each element satisfies (0 \le a_i \le k) for all (1 \le i \le n). You can perform the following operation on the array: Choose two distinct indices (i) and (j) ((1 \le i,j \le n) and (i \neq j)) such that (a_i + a_j = k). Select an integer (x) satisfying (-a_j \le x \le a_i). Decrease (a_i) by (x) and increase (a_j) by (x). In other words, update (a_i := a_i - x) and (a_j := a_j + x). Note that the constraints on (x) ensure that all elements of array (a) remain between (0) and (k) throughout the operations. Your task is to determine whether it is possible to make the array (a) non-decreasing(^{\text{∗}}) using the above operation. If it is possible, find a sequence of at most (3n) operations that transforms the array into a non-decreasing one. It can be proven that if it is possible to make the array non-decreasing using the above operation, there exists a solution that uses at most (3n) operations. (^{\text{∗}}) An array (a_1, a_2, \ldots, a_n) is said to be non-decreasing if for all (1 \le i \le n - 1), it holds that (a_i \le a_{i+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 two integers, (n) and (k) ((4 \le n \le 2 \cdot 10^5), (1 \le k \le 10^9)) — the length of the array (a) and the required sum for the operation. The second line of each test case contains (n) integers (a_1, a_2, \ldots, a_n) ((0 \le a_i \le k)) — the elements of array (a). It is guaranteed that the sum of (n) over all test cases does not exceed (2 \cdot 10^5). For each test case, output (-1) if it is not possible to make the array non-decreasing using the operation. Otherwise, output the

Tutorials

142149

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
316586500 KumaTachiRen E April 21, 2025, 4:23 p.m. OK C# 10 TESTS 103 358 95846400
316626948 xiaohaoyu7c03 E April 22, 2025, 2:53 a.m. OK C++17 (GCC 7-32) TESTS 103 608 31948800
316598946 andrej246 E April 21, 2025, 5:39 p.m. OK C++17 (GCC 7-32) TESTS 103 609 51609600
316632945 11490DX E April 22, 2025, 4:33 a.m. OK C++17 (GCC 7-32) TESTS 103 656 26726400
316632479 Legendary_Noxus E April 22, 2025, 4:25 a.m. OK C++17 (GCC 7-32) TESTS 103 656 37785600
316596998 demoralizer E April 21, 2025, 5:26 p.m. OK C++17 (GCC 7-32) TESTS 103 687 53452800
316584826 JakobZ E April 21, 2025, 4:19 p.m. OK C++17 (GCC 7-32) TESTS 103 749 41574400
316637265 mandy0109 E April 22, 2025, 5:35 a.m. OK C++17 (GCC 7-32) TESTS 103 780 43827200
316626467 Mindeveloped E April 22, 2025, 2:44 a.m. OK C++17 (GCC 7-32) TESTS 103 827 28467200
316599922 timg8710 E April 21, 2025, 5:47 p.m. OK C++17 (GCC 7-32) TESTS 103 936 30515200
316620916 FattyPenguin E April 22, 2025, 12:45 a.m. OK C++17 (GCC 7-32) TESTS 103 1046 25907200
316600158 kwoncycle E April 21, 2025, 5:49 p.m. OK C++20 (GCC 13-64) TESTS 103 311 48742400
316636601 LuOH3_ E April 22, 2025, 5:26 a.m. OK C++20 (GCC 13-64) TESTS 103 359 19456000
316594732 flashmt E April 21, 2025, 5:13 p.m. OK C++20 (GCC 13-64) TESTS 103 452 20684800
316580737 Fysty E April 21, 2025, 4:09 p.m. OK C++20 (GCC 13-64) TESTS 103 452 30412800
316629770 TRDOG E April 22, 2025, 3:42 a.m. OK C++20 (GCC 13-64) TESTS 103 452 113561600
316595391 Khalid_Kamal_ E April 21, 2025, 5:15 p.m. OK C++20 (GCC 13-64) TESTS 103 453 27340800
316582948 AmirAli-Asgari E April 21, 2025, 4:14 p.m. OK C++20 (GCC 13-64) TESTS 103 468 30310400
316600438 noya2 E April 21, 2025, 5:51 p.m. OK C++20 (GCC 13-64) TESTS 103 483 20684800
316624417 Aurorawlm E April 22, 2025, 2:06 a.m. OK C++20 (GCC 13-64) TESTS 103 484 50995200
316587810 Rubikun E April 21, 2025, 4:26 p.m. OK C++20 (GCC 13-64) TESTS 103 514 32256000
316601359 FzArK E April 21, 2025, 5:58 p.m. OK C++23 (GCC 14-64, msys2) TESTS 103 405 29798400
316600297 FzArK E April 21, 2025, 5:50 p.m. OK C++23 (GCC 14-64, msys2) TESTS 103 406 29798400
316635059 jlass_ E April 22, 2025, 5:04 a.m. OK C++23 (GCC 14-64, msys2) TESTS 103 421 28979200
316616191 Boboge E April 21, 2025, 8:24 p.m. OK C++23 (GCC 14-64, msys2) TESTS 103 421 28979200
316618895 SomethingNew E April 21, 2025, 8:59 p.m. OK C++23 (GCC 14-64, msys2) TESTS 103 421 55808000
316619042 Tamatem.1 E April 21, 2025, 9:01 p.m. OK C++23 (GCC 14-64, msys2) TESTS 103 452 27340800
316629921 Maillew E April 22, 2025, 3:45 a.m. OK C++23 (GCC 14-64, msys2) TESTS 103 452 50176000
316596724 miumah E April 21, 2025, 5:24 p.m. OK C++23 (GCC 14-64, msys2) TESTS 103 453 45158400
316599604 NovusStellachan E April 21, 2025, 5:44 p.m. OK C++23 (GCC 14-64, msys2) TESTS 103 468 36864000
316581746 244mhq E April 21, 2025, 4:11 p.m. OK C++23 (GCC 14-64, msys2) TESTS 103 483 30310400
316635133 ahmedafeef E April 22, 2025, 5:05 a.m. OK GNU C11 TESTS 103 1484 9728000
316583801 xxh1999 E April 21, 2025, 4:16 p.m. OK PyPy 3-64 TESTS 103 1062 130048000
316596292 JakeMate14 E April 21, 2025, 5:21 p.m. OK Rust 2021 TESTS 103 233 22425600
316594909 tanriol E April 21, 2025, 5:13 p.m. OK Rust 2021 TESTS 103 531 121958400

remove filters

Back to search problems