Codeforces Round 1053 (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
2150 Codeforces Round 1053 (Div. 1) FINISHED False 11700 17691923 Sept. 24, 2025, 11:35 a.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 2623 ) C Limited Edition Shop PROGRAMMING data structures dp

There is a shop with (n) objects numbered from (1) to (n), and only one copy of each object. According to you, the objects have values (v_1, v_2, \ldots, v_n) (which can be negative). Alice and Bob have their own order of preference of objects ((a_1, a_2, \ldots, a_n) and (b_1, b_2, \ldots, b_n) respectively). In particular, Alice's favourite object is (a_1), followed by (a_2), etc.; Bob's favourite object is (b_1), followed by (b_2), etc. For (n) times, one of them goes to the shop and buys her or his most favourite object still in the shop. At the end, Alice and Bob have their own sets of objects. Now the shop is empty, and you wonder whether Alice's preferences are similar to yours. Over all sets of objects that Alice could have bought, what's the maximum sum of values according to you? 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 number of objects. The second line of each test case contains (n) integers (v_1, v_2, \ldots, v_n) ((-10^9 \le v_i \le 10^9)) — the values of the objects, according to you. The third line of each test case contains (n) integers (a_1, a_2, \ldots, a_n) ((1 \le a_i \le n)) — Alice's order of preference. The (a_i) are distinct. The fourth line of each test case contains (n) integers (b_1, b_2, \ldots, b_n) ((1 \le b_i \le n)) — Bob's order of preference. The (b_i) are distinct. It is guaranteed that the sum of (n) over all test cases does not exceed (2 \cdot 10^5). For each test case, output a single integer: the maximum sum of values over all sets of objects that Alice could have bought. In the first test case, Alice can buy the sets of objects ([]) (empty), (1), (3), (3, 1), $$$3, 1, 2$$

Tutorials

Editorial of Codeforces Round 1053 (Div. 1, Div. 2)

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
340180074 KumaTachiRen C Sept. 24, 2025, 12:51 p.m. OK C# 13 TESTS 40 515 15052800
340171753 JaeminPark C Sept. 24, 2025, 12:27 p.m. OK C++17 (GCC 7-32) TESTS 40 249 2457600
340171302 fengqiyuka C Sept. 24, 2025, 12:26 p.m. OK C++17 (GCC 7-32) TESTS 40 249 2457600
340191460 catforces C Sept. 24, 2025, 1:29 p.m. OK C++17 (GCC 7-32) TESTS 40 296 6451200
340177249 RDFZchenyy C Sept. 24, 2025, 12:43 p.m. OK C++17 (GCC 7-32) TESTS 40 296 9625600
340221846 SoReMore C Sept. 24, 2025, 4:21 p.m. OK C++17 (GCC 7-32) TESTS 40 311 9523200
340281197 wuchenyu01 C Sept. 25, 2025, 3:33 a.m. OK C++17 (GCC 7-32) TESTS 40 343 46284800
340245907 gevak C Sept. 24, 2025, 6:36 p.m. OK C++17 (GCC 7-32) TESTS 40 390 49766400
340180659 mircea_007 C Sept. 24, 2025, 12:53 p.m. OK C++17 (GCC 7-32) TESTS 40 406 12288000
340279462 sqsfx C Sept. 25, 2025, 3:11 a.m. OK C++17 (GCC 7-32) TESTS 40 406 55398400
340216440 Splashing C Sept. 24, 2025, 3:41 p.m. OK C++17 (GCC 7-32) TESTS 40 421 28057600
340178875 www_bilibili_com C Sept. 24, 2025, 12:48 p.m. OK C++20 (GCC 13-64) TESTS 40 186 19353600
340170790 VivaciousAubergine C Sept. 24, 2025, 12:25 p.m. OK C++20 (GCC 13-64) TESTS 40 202 15462400
340168733 PEIMUDA C Sept. 24, 2025, 12:19 p.m. OK C++20 (GCC 13-64) TESTS 40 234 4915200
340173394 Revived_xryjr233 C Sept. 24, 2025, 12:32 p.m. OK C++20 (GCC 13-64) TESTS 40 234 17715200
340169774 max0810 C Sept. 24, 2025, 12:22 p.m. OK C++20 (GCC 13-64) TESTS 40 249 10956800
340179918 fyable C Sept. 24, 2025, 12:51 p.m. OK C++20 (GCC 13-64) TESTS 40 265 8908800
340177964 Sin_Watt C Sept. 24, 2025, 12:45 p.m. OK C++20 (GCC 13-64) TESTS 40 265 13312000
340175986 dorijanlendvaj C Sept. 24, 2025, 12:39 p.m. OK C++20 (GCC 13-64) TESTS 40 265 16281600
340164012 Otomachi_Una C Sept. 24, 2025, 12:07 p.m. OK C++20 (GCC 13-64) TESTS 40 265 20889600
340185270 Richard1211 C Sept. 24, 2025, 1:08 p.m. OK C++20 (GCC 13-64) TESTS 40 265 50278400
340195637 Lovely_Lyn C Sept. 24, 2025, 1:44 p.m. OK C++23 (GCC 14-64, msys2) TESTS 40 187 235417600
340268847 Benq C Sept. 25, 2025, 12:33 a.m. OK C++23 (GCC 14-64, msys2) TESTS 40 202 9625600
340162611 maroonrk C Sept. 24, 2025, 12:04 p.m. OK C++23 (GCC 14-64, msys2) TESTS 40 202 10444800
340162632 maspy C Sept. 24, 2025, 12:04 p.m. OK C++23 (GCC 14-64, msys2) TESTS 40 217 17510400
340177792 raincity C Sept. 24, 2025, 12:44 p.m. OK C++23 (GCC 14-64, msys2) TESTS 40 218 4915200
340182023 fydj C Sept. 24, 2025, 12:58 p.m. OK C++23 (GCC 14-64, msys2) TESTS 40 218 20582400
340226161 424479543 C Sept. 24, 2025, 4:54 p.m. OK C++23 (GCC 14-64, msys2) TESTS 40 233 12800000
340218270 424479543 C Sept. 24, 2025, 3:54 p.m. OK C++23 (GCC 14-64, msys2) TESTS 40 234 16588800
340197824 exgcd C Sept. 24, 2025, 1:52 p.m. OK C++23 (GCC 14-64, msys2) TESTS 40 264 9011200
340184375 kaIimm C Sept. 24, 2025, 1:05 p.m. OK C++23 (GCC 14-64, msys2) TESTS 40 265 7372800
340193641 nathanballman C Sept. 24, 2025, 1:36 p.m. OK Java 21 TESTS 40 812 16896000
340163321 arvindf232 C Sept. 24, 2025, 12:06 p.m. OK Kotlin 2.2 TESTS 40 749 8704000
340208646 Ayis137 C Sept. 24, 2025, 2:36 p.m. OK Kotlin 2.2 TESTS 40 1030 31744000
340191079 Z_actuary C Sept. 24, 2025, 1:27 p.m. OK PyPy 3-64 TESTS 40 905 47001600
340174916 toam C Sept. 24, 2025, 12:36 p.m. OK PyPy 3-64 TESTS 40 1046 37888000
340275582 smilences C Sept. 25, 2025, 2:06 a.m. OK PyPy 3-64 TESTS 40 1874 50585600
340186116 sansen C Sept. 24, 2025, 1:10 p.m. OK Rust 2021 TESTS 40 468 30412800
340162304 Egor C Sept. 24, 2025, 12:03 p.m. OK Rust 2024 TESTS 40 343 15974400

remove filters

Back to search problems