Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int INF = 987654321;
const ll MOD = 1000000007LL;

ll ipow(ll base, ll exp)
{
    ll result = 1LL;
    for (;;)
    {
        if (exp & 1)
            result *= base;
        exp >>= 1;
        if (!exp)
            break;
        base *= base;
    }

    return result;
}

//const long double PI = (acos(-1));
//const long double EPS = 0.0000000001;

int n, m;
vi a;
map<ll, ll> record;

int main(void) {
    ios_base::sync_with_stdio(false); 
    cin.tie(0); 
    cout.tie(0);
    //freopen("in.txt", "r", stdin);
    cin >> n >> m;
    a.resize(n);
    rep(i,0,n) {
        cin >> a[i];
    }
    rep(i,0,m) {
        ll b, c;
        cin >> b >> c;
        if(record.find(c) != record.end()) {
            record[c] += b;
        } else {
            record[c] = b;
        }
    }

    ll cnt = n;
    auto it = record.rbegin();
    while(cnt > 0 && it != record.rend()) {
        ll b = max(it->S, n);
        ll c = it->F;
        //cout << b << " : " << c << endl;
        for(int i=0; i<b; ++i) {
            a.pb(c);
        }
        cnt -= b;
        it++;
    }

    sort(all(a));

    ll total = 0;
    per(i,sz(a)-n,sz(a)) {
        total += (ll)a[i];
    }

    cout << total << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:65:19: error: no matching function for call to 'max(long long int&, int&)'
   65 |         ll b = max(it->S, n);
      |                ~~~^~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/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:65:19: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   65 |         ll b = max(it->S, n);
      |                ~~~^~~~~~~~~~
/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:
/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:65:19: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   65 |         ll b = max(it->S, n);
      |                ~~~^~~~~~~~~~