Company: Google
Difficulty: hard
You are given three arrays A , B and C of length N . For each index i , A[i] is greater than or equal to B[i] . You can perform the given operation on the array A as many times as you want. In each operation: Pick any two indices i and j , add 1 to A[i] and subtract 1 from A[j] . This operation can only be done if A[j] is currently greater than B[j] . The cost of this single operation is C[j] . Note: 1-based indexing is used. Task If you perform the operations optimally, determine the maximum possible minimum number present in the final array A , and also find the minimum cost required to make this possible. As this cost can be very large, print it modulo 10 9 + 7. Example Assumptions: N = 5, A = [1, 2, 2, 3, 3], B = [1, 2, 1, 2, 1], C = [1, 2, 1, 4, 3]. Approach: the only optimal approach is to choose index 1 as i and index 5 as j and perform the operation on them. The array A after that will be [2, 2, 2, 3, 2]. The maximum possible minimum number in A is 2, and the minimum cost requi