Codeforces Round 1020 (Div. 3)

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
2106 Codeforces Round 1020 (Div. 3) FINISHED False 8100 30900323 April 24, 2025, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 25501 ) C Cherry Bomb PROGRAMMING greedy math sortings

Two integer arrays (a) and (b) of size (n) are complementary if there exists an integer (x) such that (a_i + b_i = x) over all (1 \le i \le n). For example, the arrays (a = 2, 1, 4) and (b = 3, 4, 1) are complementary, since (a_i + b_i = 5) over all (1 \le i \le 3). However, the arrays (a = 1, 3) and (b = 2, 1) are not complementary. Cow the Nerd thinks everybody is interested in math, so he gave Cherry Bomb two integer arrays (a) and (b). It is known that (a) and (b) both contain (n) non-negative integers not greater than (k). Unfortunately, Cherry Bomb has lost some elements in (b). Lost elements in (b) are denoted with (-1). Help Cherry Bomb count the number of possible arrays (b) such that: (a) and (b) are complementary . All lost elements are replaced with non-negative integers no more than (k). The first line of the input contains a single integer (t) ((1 \le t \le 10^4)) — the number of test cases. The first line of each test case contains two integers (n) and (k) ((1 \le n \le 2 \cdot 10^5), (0 \le k \le 10^9)) — the size of the arrays and the maximum possible value of their elements. The second line contains (n) integers (a_1, a_2, ..., a_n) ((0 \le a_i \le k)). The third line contains (n) integers (b_1, b_2, ..., b_n) ((-1 \le b_i \le k)). If (b_i = -1), then this element is missing. It is guaranteed that the sum of (n) over all test cases does not exceed (2 \cdot 10^5). Output exactly one integer, the number of ways Cherry Bomb can fill in the missing elements from (b) such that (a) and (b) are complementary. In the first example, the only way to fill in the missing elements in (b) such that (a) and (b) are complementary is if (b = 2, 0, 1). In the second example, there is no way to fill in the missing elements of (b) such that (a) and (b)

Tutorials

Codeforces Round 1020 (Div. 3) Editorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
317087960 A1ternate C April 24, 2025, 5:59 p.m. OK C# 10 TESTS 7 171 32972800
317130879 johnnyftb C April 25, 2025, 5:17 a.m. OK C++17 (GCC 7-32) TESTS 7 93 0
317129876 LiangLiangLe C April 25, 2025, 5:02 a.m. OK C++17 (GCC 7-32) TESTS 7 93 0
317120597 Skittle_06 C April 25, 2025, 2:09 a.m. OK C++17 (GCC 7-32) TESTS 7 93 0
317118997 mainnahihoo C April 25, 2025, 1:34 a.m. OK C++17 (GCC 7-32) TESTS 7 93 0
317115305 Hans-234 C April 25, 2025, 12:15 a.m. OK C++17 (GCC 7-32) TESTS 7 93 0
317098131 binary_ninja C April 24, 2025, 7:33 p.m. OK C++17 (GCC 7-32) TESTS 7 93 0
317091914 yaaashhh725 C April 24, 2025, 6:33 p.m. OK C++17 (GCC 7-32) TESTS 7 93 0
317091324 Sarav_24 C April 24, 2025, 6:28 p.m. OK C++17 (GCC 7-32) TESTS 7 93 0
317087425 akashpaswan845 C April 24, 2025, 5:54 p.m. OK C++17 (GCC 7-32) TESTS 7 93 0
317083654 _ratul_ C April 24, 2025, 5:24 p.m. OK C++17 (GCC 7-32) TESTS 7 93 0

remove filters

Back to search problems