Language: C++

#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <bitset>
#include <iterator>
#include <valarray>
#include <complex>
#include <utility>
#include <string>
#include <sstream>
#include <tuple>
#include <initializer_list>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <fstream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define all(c) (c).begin(),(c).end()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using tii = tuple<int, int>;
using tll = tuple<ll, ll>;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
#ifdef DBG
template<typename T> ostream &operator<<(ostream &os, set<T> const &s) { if (s.size() == 0) return os << "{}"; os << "{"; decltype(s.begin()) iter; for (iter = s.begin(), ++iter; iter != s.end(); ++iter) { --iter; os << *iter << ", "; ++iter; } --iter; os << *iter << '}'; return os; }
template<typename T> ostream &operator<<(ostream &os, multiset<T> const &s) { if (s.size() == 0) return os << "{}"; os << "{"; decltype(s.begin()) iter; for (iter = s.begin(), ++iter; iter != s.end(); ++iter) { --iter; os << *iter << ", "; ++iter; } --iter; os << *iter << '}'; return os; }
template<typename T, typename U> ostream &operator<<(ostream &os, map<T, U> const &mp) { if (mp.size() == 0) return os << "{}"; os << "{" << endl; decltype(mp.begin()) iter; for (iter = mp.begin(), ++iter; iter != mp.end(); ++iter) { --iter; os << "  {" << iter->first << ", " << iter->second << "}," << endl; ++iter; } --iter; os << "  {" << iter->first << ", " << iter->second << "}" << endl << '}'; return os; }
template<typename T> ostream &operator<<(ostream &os, unordered_set<T> const &s) { if (s.size() == 0) return os << "{}"; os << "{"; decltype(s.begin()) iter; for (iter = s.begin(), ++iter; iter != s.end(); ++iter) { --iter; os << *iter << ", "; ++iter; } --iter; os << *iter << '}'; return os; }
template<typename T> ostream &operator<<(ostream &os, unordered_multiset<T> const &s) { if (s.size() == 0) return os << "{}"; os << "{"; decltype(s.begin()) iter; for (iter = s.begin(), ++iter; iter != s.end(); ++iter) { --iter; os << *iter << ", "; ++iter; } --iter; os << *iter << '}'; return os; }
template<typename T, typename U> ostream &operator<<(ostream &os, unordered_map<T, U> const &mp) { if (mp.size() == 0) return os << "{}"; os << "{" << endl; decltype(mp.begin()) iter; for (iter = mp.begin(), ++iter; iter != mp.end(); ++iter) { --iter; os << "  {" << iter->first << ", " << iter->second << "}," << endl; ++iter; } --iter; os << "  {" << iter->first << ", " << iter->second << "}" << endl << '}'; return os; }
template<typename T> ostream &operator<<(ostream &os, vector<T> const &v) { os << '['; rep(i, v.size()-1) os << v[i] << ", "; if (v.size() > 0) os << v[v.size()-1]; cerr << ']'; return os; }
template<typename T, unsigned N, unsigned Last> struct TuplePrinter { static void print(ostream &os, T const& v) { os << std::get<N>(v) << ", "; TuplePrinter<T, N + 1, Last>::print(os, v); } };
template<typename T, unsigned N> struct TuplePrinter<T, N, N> { static void print(ostream &os, T const &v) { os << std::get<N>(v); } };
template<typename... Types> ostream& operator<<(ostream &os, tuple<Types...> const &v) { os << "("; TuplePrinter<tuple<Types...>, 0, sizeof...(Types) - 1>::print(os, v); os << ")"; return os; }
template<typename T> void _dbg(T const &t) { cerr << t << endl; }
template<typename T, typename... Args> void _dbg(T const &t, Args... args) { cerr << t << " "; _dbg(args...); }
template<typename... Args> void __dbg(const char *fn, int l, Args... args) { cerr << "[" << fn << ":" << l << "] "; _dbg(args...); }
#define dbg(...) __dbg(__func__, __LINE__, __VA_ARGS__)
#else
#define dbg(...)
#endif
const ll infty = 1223372036854775807LL;
const int inf_int = 987654321;
const double eps = 1e-8;

void solve() {
    int n, m;
    cin >> n >> m;
    vi price(n);
    rep(i, n) cin >> price[i];
    vector<tuple<int, int, int>> extprice; // <price, idx, num_used_tickets>
    rep(i, n) {
        int p = 0;
        for (;;) {
            int cur_p = price[i] >> p;
            if (cur_p == 0) break;
            extprice.emplace_back(cur_p, i, p);
            p += 1;
        }
    }
    sort(all(extprice));
    vi cnt(n, inf_int);
    rep(i, max(0ULL, extprice.size() - m)) {
        int price, idx, n_tickets;
        tie(price, idx, n_tickets) = extprice[i];
        chmin(cnt[idx], n_tickets);
    }
    ll ans = 0;
    rep(i, n) {
        if (cnt[i] < inf_int) {
            ans += (price[i] >> cnt[i]);
        }
    }
    cout << ans << endl;
}

int main() {
#ifdef DBG
    ifstream cin("in.txt");
    std::cin.rdbuf(cin.rdbuf());
    //ofstream cout("out.txt");
    //std::cout.rdbuf(cout.rdbuf());
#else
    ios_base::sync_with_stdio(false);
    std::cin.tie(0);
#endif
    solve();
    return 0;
}


Compiler output:
a.cc: In function 'void solve()':
a.cc:82:15: error: no matching function for call to 'max(long long unsigned int, std::vector<std::tuple<int, int, int> >::size_type)'
   82 |     rep(i, max(0ULL, extprice.size() - m)) {
      |            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:30:45: note: in definition of macro 'rep'
   30 | #define rep(i, n) for (int i = 0; i < (int)(n); ++i)
      |                                             ^
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:82:15: note:   deduced conflicting types for parameter 'const _Tp' ('long long unsigned int' and 'std::vector<std::tuple<int, int, int> >::size_type' {aka 'long unsigned int'})
   82 |     rep(i, max(0ULL, extprice.size() - m)) {
      |            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:30:45: note: in definition of macro 'rep'
   30 | #define rep(i, n) for (int i = 0; i < (int)(n); ++i)
      |                                             ^
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:8:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:82:15: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long unsigned int'
   82 |     rep(i, max(0ULL, extprice.size() - m)) {
      |            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:30:45: note: in definition of macro 'rep'
   30 | #define rep(i, n) for (int i = 0; i < (int)(n); ++i)
      |                                             ^