classSolution{public:intmaxCoins(vector<int>&piles){ranges::sort(piles);intans=0;// piles = [S S M L M L], pick all the M.for(inti=piles.size()/3;i<piles.size();i+=2)ans+=piles[i];returnans;}};
1 2 3 4 5 6 7 8 910111213
classSolution{publicintmaxCoins(int[]piles){Arrays.sort(piles);intans=0;// piles = [S S M L M L], pick all the M.for(inti=piles.length/3;i<piles.length;i+=2)ans+=piles[i];returnans;}}