package leetcode;

/**
 * https://leetcode.com/problems/maximum-number-of-coins-you-can-get/
 */
public class Problem1561 {
    public int maxCoins(int[] piles) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1561 prob = new Problem1561();
        System.out.println(prob.maxCoins(new int[]{2,4,1,2,7,8})); // 9
        System.out.println(prob.maxCoins(new int[]{2,4,5})); // 4
        System.out.println(prob.maxCoins(new int[]{9,8,7,6,5,1,2,3,4})); // 18
    }
}

@@ -12,16 +12,42 @@
 tcode;%0A%0A
+import java.util.Arrays;%0A%0A
 /**%0A * h
@@ -194,38 +194,56 @@
     
-// TODO%0A        return
+Arrays.sort(piles);%0A        int answer =
  0;%0A    
 %7D%0A%0A 
@@ -242,318 +242,136 @@
     
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem1561 prob = new Problem1561();%0A        System.out.println(prob.maxCoins(new int%5B%5D%7B2,4,1,2,7,8%7D)); // 9%0A        System.out.println(prob.maxCoins(new int%5B%5D%7B2,4,5%7D)); // 4%0A        System.out.println(prob.maxCoins(new int%5B%5D%7B9,8,7,6,5,1,2,3,4%7D)); // 18
+for (int i = 0, j = piles.length - 2; i %3C j; i++, j -= 2) %7B%0A            answer += piles%5Bj%5D;%0A        %7D%0A        return answer;
 %0A   

Solve exercise 1561