2952.cpp (440B)
1 class Solution { 2 public: 3 int minimumAddedCoins(vector<int> &coins, int target) const { 4 int res = 0, get = 0; 5 6 sort(begin(coins), end(coins)); 7 for (int i = 0; i < size(coins) && get < target; i++) { 8 while (get + 1 < coins[i]) 9 get += get + 1, res++; 10 get += coins[i]; 11 } 12 13 while (get < target) 14 get += get + 1, res++; 15 16 return res; 17 } 18 };