Language: C++

//
//  main.cpp
//  Chokudai_Contest_004
//
//  Created by tolemy on 2019/08/31.
//  Copyright © 2019 tolemy. All rights reserved.
//

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

#define rep(i, start, end) for (int i = (int)(start); i < (int)(end); i++)

class Item
{
public:
    int value;
    int discountValue;
    Item(int p_value)
    {
        value = p_value;
        int discount = value / 2;
        discountValue = value - discount;
    }
};

int main(int argc, const char *argv[])
{

    int n, m;
    cin >> n >> m;

    auto a = [](Item x, Item y) { return x.discountValue < y.discountValue; };
    priority_queue<Item, vector<Item>, function<bool(Item, Item)>> pq(a);

    rep(i, 0, n)
    {
        int v;
        cin >> v;

        Item a(v);
        pq.push(v);
    }

    rep(i, 0, m)
    {
        Item a = pq.top();
        pq.pop();

        Item b(a.value - a.discountValue);
        pq.push(b);
    }

    long long int sum = 0;
    while (!pq.empty())
    {
        Item a = pq.top();
        pq.pop();

        sum += a.value;
    }

    cout << sum << endl;

    return 0;
}


Compiler output:
a.cc: In function 'int main(int, const char**)':
a.cc:38:40: error: 'function' was not declared in this scope
   38 |     priority_queue<Item, vector<Item>, function<bool(Item, Item)>> pq(a);
      |                                        ^~~~~~~~
a.cc:12:1: note: 'std::function' is defined in header '<functional>'; this is probably fixable by adding '#include <functional>'
   11 | #include <queue>
  +++ |+#include <functional>
   12 | #include <vector>
a.cc:38:64: error: expression list treated as compound expression in functional cast [-fpermissive]
   38 |     priority_queue<Item, vector<Item>, function<bool(Item, Item)>> pq(a);
      |                                                                ^
a.cc:38:65: error: template argument 3 is invalid
   38 |     priority_queue<Item, vector<Item>, function<bool(Item, Item)>> pq(a);
      |                                                                 ^~
a.cc:38:71: error: invalid user-defined conversion from 'main(int, const char**)::<lambda(Item, Item)>' to 'int' [-fpermissive]
   38 |     priority_queue<Item, vector<Item>, function<bool(Item, Item)>> pq(a);
      |                                                                       ^
a.cc:37:14: note: candidate is: 'constexpr main(int, const char**)::<lambda(Item, Item)>::operator bool (*)(Item, Item)() const' (near match)
   37 |     auto a = [](Item x, Item y) { return x.discountValue < y.discountValue; };
      |              ^
a.cc:37:14: note:   no known conversion from 'bool (*)(Item, Item)' to 'int'
a.cc:46:12: error: request for member 'push' in 'pq', which is of non-class type 'int'
   46 |         pq.push(v);
      |            ^~~~
a.cc:51:21: error: request for member 'top' in 'pq', which is of non-class type 'int'
   51 |         Item a = pq.top();
      |                     ^~~
a.cc:52:12: error: request for member 'pop' in 'pq', which is of non-class type 'int'
   52 |         pq.pop();
      |            ^~~
a.cc:55:12: error: request for member 'push' in 'pq', which is of non-class type 'int'
   55 |         pq.push(b);
      |            ^~~~
a.cc:59:16: error: request for member 'empty' in 'pq', which is of non-class type 'int'
   59 |     while (!pq.empty())
      |                ^~~~~
a.cc:61:21: error: request for member 'top' in 'pq', which is of non-class type 'int'
   61 |         Item a = pq.top();
      |                     ^~~
a.cc:62:12: error: request for member 'pop' in 'pq', which is of non-class type 'int'
   62 |         pq.pop();
      |            ^~~