3out1in This problem has subtasks. Given an array π΅ B containing π M (where π M isβ¦
- User
3out1in This problem has subtasks.
Given an array π΅ B containing π M (where π M is odd) integers, you have to perform the following operation on π΅ B until it consists of only a single element.
Choose distinct indices π , i, π , j, π k of the array π΅ B. Remove π΅ π , π΅ π , π΅ π B i β ,B j β ,B k β from the array. Append ( π΅ π + π΅ π β π΅ π ) (B i β +B j β βB k β ) to π΅ B. Note that the operation reduces the length of π΅ B by 2 2. For example, if π΅
[ 2 , 5 , 3 , 4 , 2 ] B=[2,5,3,4,2], you can choose indices ( 3 , 1 , 4 ) (3,1,4), delete the values π΅ 3 , π΅ 1 , π΅ 4 B 3 β ,B 1 β ,B 4 β from π΅ B, and append π΅ 3 + π΅ 1 β π΅ 4
3 + 2 β 4
1 B 3 β +B 1 β βB 4 β =3+2β4=1 to it, obtaining π΅
[ 5 , 2 , 1 ] B=[5,2,1].
Your aim is to maximize the value of the final element remaining in the array. Let this maximum value be π ( π΅ ) f(B).
You are given an array π΄ A of length π N. Answer π Q queries on it.
In the π i-th query, you are given an integer πΎ π K i β , which is guaranteed to be odd. Compute π ( [ π΄ 1 , π΄ 2 , β¦ , π΄ πΎ π ] ) f([A 1 β ,A 2 β ,β¦,A K i β
β ]). That is, compute the answer when considering only the first πΎ π K i β elements of π΄ A.
Each query is independent, so the array remains unchanged across queries.
Input Format The first line of input will contain a single integer π T, denoting the number of test cases. Each test case consists of three lines of input. The first line of each test case contains two space-separated integers π N and π Q β the length of the array and the number of queries. The second line contains π N space-separated integers π΄ 1 , π΄ 2 , β¦ , π΄ π A 1 β ,A 2 β ,β¦,A N β . The third line contains π Q space-separated integers πΎ 1 , πΎ 2 , β¦ , πΎ π K 1 β ,K 2 β ,β¦,K Q β . Output Format For each test case, output π Q space-separated numbers: the answers for each query in order.
Constraints 1 β€ π β€ 1 0 5 1β€Tβ€10 5
1 β€ π β€ 2 β 1 0 5 1β€Nβ€2β 10 5
1 β€ π β€ β π 2 β 1β€Qβ€β 2 N β β β 1 0 9 β€ π΄ π β€ 1 0 9 β10 9 β€A i β β€10 9 for each 1 β€ π β€ π 1β€iβ€N 1 β€ πΎ π β€ π 1β€K i β β€N for each 1 β€ π β€ π 1β€iβ€Q πΎ π K i β is odd The sum of π N over all test cases won't exceed 2 β 1 0 5 2β 10 5
Subtasks Subtask 1 (30 points): 1 β€ π β€ 5 1β€Qβ€5. Subtask 2 (70 points): No further constraints. Sample 1: Input Output 1 5 3 3 -1 2 4 5 3 1 5 6 3 11 Explanation: Query 1 1: The array to consider is [ 3 , β 1 , 2 ] [3,β1,2]. It's optimal to choose the triple of indices ( 1 , 3 , 2 ) (1,3,2), which turns the array into [ 6 ] [6] (since π΄ 1 + π΄ 3 β π΄ 2
3 + 2 β ( β 1 )
6 A 1 β +A 3 β βA 2 β =3+2β(β1)=6). This is optimal.
Query 2 2: The array to consider is [ 3 ] [3]. No operations can be performed, and the answer is just 3 3.
Query 3 3: Now, we consider the full array. One optimal sequence of moves is:
- Assistant