Question: Task 3 You are given an array A consisting of N integers ( N is divisible by 3 ) and an integer K . In

Task 3
You are given an array A consisting of N integers ( N is divisible by 3) and an integer K. In one move, you can increase or decrease any element of A by 1. The task is to modify array A using such moves in order to maximize the difference between the (N3)th largest element and the (N3) th smallest element of the resulting array. You can perform at most K moves.
For example, array A=[9,12,15,5,7,13] consists of N=6 elements, so the (N/3)th (that is, the 2 nd ) largest element is 13 and the (N3)th (2nd) smallest element is 7.
Write a function:
int solution(vectorAK(N3)(N3)A=[8,8,8,7,7,7,7,7,7,7,-8,-8]K=17,7,7,7,-8,-8A=[-5,1,1,4,4,4,7,4,6]K=6-5,0,0,4,4,7,7,4,7n
Exampre.
Given [8,8,8,7,7,7,7,7,7,7,-8,-8
Task 3 You are given an array A consisting of N

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Finance Questions!