#include <bits/stdc++.h>
using namespace std;
int minArraySum(vector<int> nums, int k, int op1, int op2) {
for (int step = 0; step < op1 + op2; ++step) {
std::sort(nums.rbegin(), nums.rend());
if (op2 > 0 && nums[0] >= k) {
nums[0] -= k;
--op2;
} else if (op1 > 0) {
nums[0] = (nums[0] + 1) / 2;
--op1;
} else {
break;
}
}
int totalSum = 0;
for (int num : nums) {
totalSum += num;
}
return totalSum;
}
int main() {
// your code goes here
int ans = minArraySum({2,8,3,19,3}, 3,1,1);
cout<<ans;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCBtaW5BcnJheVN1bSh2ZWN0b3I8aW50PiBudW1zLCBpbnQgaywgaW50IG9wMSwgaW50IG9wMikgewogICAgIGZvciAoaW50IHN0ZXAgPSAwOyBzdGVwIDwgb3AxICsgb3AyOyArK3N0ZXApIHsKICAgICAgICBzdGQ6OnNvcnQobnVtcy5yYmVnaW4oKSwgbnVtcy5yZW5kKCkpOwoKICAgICAgICBpZiAob3AyID4gMCAmJiBudW1zWzBdID49IGspIHsKICAgICAgICAgICAgbnVtc1swXSAtPSBrOwogICAgICAgICAgICAtLW9wMjsKICAgICAgICB9IGVsc2UgaWYgKG9wMSA+IDApIHsKICAgICAgICAgICAgbnVtc1swXSA9IChudW1zWzBdICsgMSkgLyAyOwogICAgICAgICAgICAtLW9wMTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBicmVhazsgCiAgICAgICAgfQogICAgfQogICAgaW50IHRvdGFsU3VtID0gMDsKICAgIGZvciAoaW50IG51bSA6IG51bXMpIHsKICAgICAgICB0b3RhbFN1bSArPSBudW07CiAgICB9CgogICAgcmV0dXJuIHRvdGFsU3VtOwogICAgfQppbnQgbWFpbigpIHsKCS8vIHlvdXIgY29kZSBnb2VzIGhlcmUKaW50IGFucyA9IG1pbkFycmF5U3VtKHsyLDgsMywxOSwzfSwgMywxLDEpOwoJY291dDw8YW5zOwoJcmV0dXJuIDA7Cn0=