Note that 0-based indexing is used throughout the problem.
You are given an array a of length n and k non-empty sets of integers from 0 to n−1. Let S_p denote the p-th set. Each integer from 0 to n−1 belongs to exactly one of those sets. It is guaranteed that 0 belongs to S_0.
You choose a \uline{nonincreasing} array c of nonnegative reals. c_0 must be positive. Let d_p denote ∑_i∈S_pc_ia_i. Let X denote d_0min_p=1k−1d_p. What is the maximum value of X you can obtain by choosing c accordingly?
The first line contains two integers n and k (2≤n≤4⋅104,2≤k≤4), the length of a and the number of sets.
The second line contains n integers a_i (1≤a_i≤109), the elements of a.
The third line contains n integers b_i (b_0=0,0≤b_i<k) meaning that i belongs to S_b_i.
All sets S_p are non-empty. In other words, all integers from 0 to k−1 occur at least once among b_i.
Print a single integer --- the maximum value of X you can obtain accurate to absolute or relative error of at most 10−4.