classSolution { public: intgetMaximumConsecutive(vector<int>& coins){ int r = 0; // start from [0, r]. sort(coins.begin(), coins.end()); for (int coin : coins) { // to make [0, r] & [coin, coin + r] connected, // coin should not be greater than 'r + 1'. if (coin <= r + 1) r += coin; elsebreak; } return r + 1; } };