Bonk in bag candy question using set

 avatar
user_6075971
plain_text
2 years ago
827 B
0
Indexable
Never
#include <iostream>
#include <set>
using namespace std;
int main()
{
    int n;
    cout << "ENTER TEST CASE--->";
    cin >> n;
    while (n--)
    {
        multiset<long long> m;
        long long n, k;
        cout << "ENTER THE BAG SIZE--->";
        cin >> n;
        cout << "ENTER THE TIME---> ";
        cin>>k;
        for (int i = 0; i < n; i++)
        {
            long long r;
            cout << "ENTER THE CANDY--->";
            cin >> r;
            m.insert(r);
        }
        int total_candy = 0;
        for (int i = 0; i < k; i++)
        {
            auto max_candy = (--m.end());
            long long candy_cnt = *max_candy;
            total_candy += candy_cnt;
            m.erase(max_candy);
                m.insert(candy_cnt / 2);
        }
        cout << total_candy;
    }
    return 0;
}