weights of exactly four integers and an integer array values of length at least four.
Pick four elements of values at indices i0 < i1 < i2 < i3 and multiply them in order by the weights; the score is weights[0]·values[i0] + weights[1]·values[i1] + weights[2]·values[i2] + weights[3]·values[i3].
Return the highest score possible. Numbers can be negative, so the answer can be negative too.weights=[2, -1, 3, 1], values=[4, -2, 1, 5, -3, 2] → 27
Take the elements at indices 0, 1, 3 and 5: 2·4 + (-1)·(-2) + 3·5 + 1·2 = 27.
weights=[1, 1, 1, 1], values=[-5, -1, -2, -3, -4] → -10
All values are negative and exactly four must be taken. Skipping -5 is best: -1 - 2 - 3 - 4 = -10.
weights=[0, 3, 0, -2], values=[7, 6, 1, 8] → 2
weights=[2, -1, 3, 1], values=[4, -2, 1, 5, -3, 2]
27
Run checks the first 3 tests in your browser. Submit checks all 100 tests on the server, hidden ones included.