fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int minArraySum(vector<int> nums, int k, int op1, int op2) {
  4. for (int step = 0; step < op1 + op2; ++step) {
  5. std::sort(nums.rbegin(), nums.rend());
  6.  
  7. if (op2 > 0 && nums[0] >= k) {
  8. nums[0] -= k;
  9. --op2;
  10. } else if (op1 > 0) {
  11. nums[0] = (nums[0] + 1) / 2;
  12. --op1;
  13. } else {
  14. break;
  15. }
  16. }
  17. int totalSum = 0;
  18. for (int num : nums) {
  19. totalSum += num;
  20. }
  21.  
  22. return totalSum;
  23. }
  24. int main() {
  25. // your code goes here
  26. int ans = minArraySum({2,8,3,19,3}, 3,1,1);
  27. cout<<ans;
  28. return 0;
  29. }
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
32