Two Arrays A and B of length N , where N is even .
There are two players kevin and paul.
Total turns = N / 2
for each turn , Kevin picks two different unused index i and j
paul picks either i or j , whichever value at index(i or j) of array B is maximum ,
if paul picks index i of Array B , then kevin picks j of Array A
else if paul picks index j of Array B, then kevin picks i of Array A
calculate sum of score of paul and sum of score of kevin for each turn
find the maximum difference of their scores.
N-> Array size
n sepated integers // Array A
n separated integers // Array B
Ex input :
N=2
1 1
1 1
Op: 0
N=4
4 2 8 6
6 5 7 8
Op : -4
N=6
7 8 2 6 10 3
9 1 3 10 2 4
Op: 8
It is not absolute value and i updated input2 with output -4. i.e Score(Kevin) - Score(paul).
As per question it was mentioned two different unused indexes. not necessary it has be ajacent , It can be any pair of indexes.
turns = N/2;
while(turns!=0){
//Kevin picks i and j // unused i and j
//Paul picks i or j from Array B whichever is max val. Let's Say B[i]
//if paul picks i , then kevin picks A[j].
scorePaul+=B[i];
scoreKevin+=A[j];
turns--;
}
diff = scoreKevin - scorePaul
return diff;