Alice and Bob take turns playing a game, with Alice starting first.

There are n stones in a pile. On each player's turn, they can remove a stone from the pile and receive points based on the stone's value. Alice and Bob may value the stones differently.

You are given two integer arrays of length n, aliceValues and bobValues. Each aliceValues[i] and bobValues[i] represents how Alice and Bob, respectively, value the ith stone.

The winner is the person with the most points after all the stones are chosen. If both players have the same amount of points, the game results in a draw. Both players will play optimally.&nbsp;Both players know the other's values.

Determine the result of the game, and:


	If Alice wins, return 1.
	If Bob wins, return -1.
	If the game results in a draw, return 0.


&nbsp;
Example 1:

Input: aliceValues = [1,3], bobValues = [2,1]
Output: 1
Explanation:
If Alice takes stone 1 (0-indexed) first, Alice will receive 3 points.
Bob can only choose stone 0, and will only receive 2 points.
Alice wins.


Example 2:

Input: aliceValues = [1,2], bobValues = [3,1]
Output: 0
Explanation:
If Alice takes stone 0, and Bob takes stone 1, they will both have 1 point.
Draw.


Example 3:

Input: aliceValues = [2,4,3], bobValues = [1,6,7]
Output: -1
Explanation:
Regardless of how Alice plays, Bob will be able to have more points than Alice.
For example, if Alice takes stone 1, Bob can take stone 2, and Alice takes stone 0, Alice will have 6 points to Bob's 7.
Bob wins.


&nbsp;
Constraints:


	n == aliceValues.length == bobValues.length
	1 &lt;= n &lt;= 105
	1 &lt;= aliceValues[i], bobValues[i] &lt;= 100


class Solution:
    def stoneGameVI(self, A, B):
        G  = [a+b for a,b in zip(A,B)]
        G.sort()
        L  = len(A)
        d  = -sum(B) + sum( G[i] for i in range(L-1,-1,-2) )
        return 1 if d>0 else ( -1 if d<0 else 0 )
class Solution 
{
static class Pair
{
        int sum=0;
        int alice=0;
        int bob=0;
    public Pair(int sum,int alice, int bob)
{
    this.sum=sum;
	this.alice = alice;
	this.bob = bob;
}
}

// class to define user defined conparator
static class Compare {
	
	static  void compare(Pair arr[], int n)
	{
		// Comparator to sort the pair according to second element
		Arrays.sort(arr, new Comparator<Pair>() {
			@Override public int compare(Pair p1, Pair p2)
			{
				return p2.sum - p1.sum;
			}
		});
		
		
	}
}
    public int stoneGameVI(int[] aliceValues, int[] bobValues)
    {
        int n=aliceValues.length;
        Pair[] a=new Pair[n];
        for(int i=0;i<n;i++)
        {
            a[i]=new Pair(aliceValues[i]+bobValues[i],aliceValues[i],bobValues[i]);
        }
        Compare.compare(a,n);
         int al=0;int bo=0;
        for(int i=0;i<n;i++)
        {
            if(i%2==0)
            {
                al+=a[i].alice;
            }
            else
            {
                bo+=a[i].bob;
            }
        }
        return Integer.compare(al,bo);
    
    
    
    }
}
vector<int> alice, bob;

struct myComp {
  bool operator()(pair<int, int>& a, pair<int, int>& b){
      return alice[a.second] + bob[a.second] < alice[b.second] + bob[b.second];
  }
};

class Solution {
public:
    int stoneGameVI(vector<int>& aliceValues, vector<int>& bobValues) {
        alice = aliceValues;
        bob = bobValues;
        priority_queue<pair<int, int>, vector<pair<int, int>>, myComp> a,b;

        for(int i=0;i<aliceValues.size();i++){
            a.push({aliceValues[i], i});
            b.push({bobValues[i], i});
        }

        int ans1, ans2;
        ans1 = ans2 = 0;
        int vis[100001] = {};

        while(a.size()){
            while(a.size() && vis[a.top().second] == 1) a.pop();
            if(a.size()){
                ans1 += a.top().first;
                vis[a.top().second] = 1;
                a.pop();
            }

            while(b.size() && vis[b.top().second] == 1) b.pop();
            if(b.size()){
                ans2 += b.top().first;
                vis[b.top().second] = 1;
                b.pop();
            }
        }

        if(ans1 == ans2) return 0;
        if(ans1 > ans2) return 1;
        return -1;
    }
};
var stoneGameVI = function(aliceValues, bobValues) {
    let aliceVal = 0
    let bobVal = 0
    let turn = true
    const combined = {}
    let n = aliceValues.length
    for (let i = 0; i < n; i++) {
        if (combined[aliceValues[i] + bobValues[i]]) {
            combined[aliceValues[i] + bobValues[i]].push({value: aliceValues[i] + bobValues[i], id: i})
        } else {
            combined[aliceValues[i] + bobValues[i]] = [{value: aliceValues[i] + bobValues[i], id: i}]
        }
    }
    Object.values(combined).reverse().forEach((value) => {
        value.forEach(val => {
            if (turn) {
                aliceVal += aliceValues[val.id]
            } else {
                bobVal += bobValues[val.id]
            }
            turn = !turn
        })
    })
    if (aliceVal === bobVal) return 0
    return aliceVal > bobVal ? 1 : -1
};
Stone Game VI