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.
Problems
B'This is the hard version of the problem. The only difference between the two versions is the constraint on m . You can make hacks only if both versions of the problem are solved. You are given an array a of length n and two integers m and k . Each element in a satisfies 1 <= a_i <= m . In one operation, you choose two indices i and j such that 1 <= i < j <= |a| , then append gcd(a_i,a_j) to the back of the array and delete a_i and a_j from the array. Note that the length of the array decreases by one after this operation. Find the maximum possible sum of the array after performing exactly k operations. The first line contains a single integer t ( 1 <= t <= 10^5 ) -- the number of test cases. The description of test cases follows. The first line of each test case contains three integers n , m and k ( 2 <= n <= 10^6 ; 1 <= m <= 9 cdot 10^{18} ; 1 <= k <= n-1 ). The second line of each test case contains n integers a_1,a_2, ldots,a_n ( 1 <= a_i <= m ). It is guaranteed that the sum of n over all test cases does not exceed 10^6 . For each test case, output the maximum possible sum of the array after performing k operations optimally. In the first test case, the best way is to choose i=1 , j=3 in the first operation. The final sequence is [7,4] . '... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
198024015 |
FatihSolak |
F2 |
March 18, 2023, 9:54 p.m. |
OK |
GNU C++17 (64) |
TESTS |
115 |
670 |
27136000 |
|
|
198034005 |
Cxny |
F2 |
March 19, 2023, 2:17 a.m. |
OK |
GNU C++17 (64) |
TESTS |
115 |
1372 |
72192000 |
|
|
198045493 |
zsxuan |
F2 |
March 19, 2023, 5:35 a.m. |
OK |
GNU C++17 (64) |
TESTS |
115 |
1387 |
80179200 |
|
|
198043074 |
njwrz |
F2 |
March 19, 2023, 5:07 a.m. |
OK |
GNU C++20 (64) |
TESTS |
115 |
483 |
56115200 |
|
|
197976181 |
AlperenT |
F2 |
March 18, 2023, 2:49 p.m. |
OK |
GNU C++20 (64) |
TESTS |
115 |
498 |
59084800 |
|
|
198029505 |
5af |
F2 |
March 19, 2023, 12:17 a.m. |
OK |
GNU C++20 (64) |
TESTS |
115 |
514 |
80179200 |
|
|
198011546 |
maypdejewpo |
F2 |
March 18, 2023, 7:13 p.m. |
OK |
GNU C++20 (64) |
TESTS |
115 |
514 |
80179200 |
|
|
197992709 |
steelxack |
F2 |
March 18, 2023, 4:35 p.m. |
OK |
GNU C++20 (64) |
TESTS |
115 |
529 |
80179200 |
|
|
198013868 |
BurnedChicken |
F2 |
March 18, 2023, 7:37 p.m. |
OK |
GNU C++20 (64) |
TESTS |
115 |
576 |
46489600 |
|
|
198023768 |
Kapt |
F2 |
March 18, 2023, 9:49 p.m. |
OK |
GNU C++20 (64) |
TESTS |
115 |
639 |
74854400 |
|
|
198030881 |
CC2021zyz |
F2 |
March 19, 2023, 12:59 a.m. |
OK |
GNU C++20 (64) |
TESTS |
115 |
732 |
98304000 |
|
|
198037471 |
dark_light |
F2 |
March 19, 2023, 3:30 a.m. |
OK |
GNU C++20 (64) |
TESTS |
115 |
858 |
93593600 |
|
|
198032114 |
xcyle |
F2 |
March 19, 2023, 1:32 a.m. |
OK |
GNU C++20 (64) |
TESTS |
115 |
997 |
52121600 |
|
|
remove filters
Back to search problems