---
# System prepended metadata

title: 1686. Stone Game VI
tags: [DP]

---

---
title: 1686. Stone Game VI
tags: DP
description: share source code.
---

# 1686. Stone Game VI

```java=
class Solution {
    
    static class Triple{
        int w;
        int a;
        int b;
        public Triple(int w, int a, int b){
            this.w = w;
            this.a = a;
            this.b = b;
        }
        
    }
    
    public int stoneGameVI(int[] aliceValues, int[] bobValues) {
        int n = aliceValues.length;
        
        List<Triple> list = new ArrayList<>();
        for(int i = 0; i < n; i ++){
            list.add( new Triple( (aliceValues[i] + bobValues[i]), aliceValues[i], bobValues[i]) );
        }
        
        Collections.sort(list, (a, b) -> b.w - a.w);
        // System.out.println(list.toString());
        
        int alice = 0;
        int bob = 0;
        
        for(int i = 0; i < n; i ++){
       
            if( i % 2 == 0){
               alice += list.get(i).a;
            }else{
                bob += list.get(i).b;
            }
        }
       // System.out.println( alice +":"+ bob);
      
        return  Integer.compare(alice, bob);
    }
}
```

