Language: C++

#include <bits/stdc++.h>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;

int main() {
  int N, M;
  cin >> N >> M;

  vector<int> A(N + 1);
  rep(i, N) scanf("%d", &A[i]);
  A[N] = INT_MAX;

  vector<pair<int, int>> BC(M);
  rep(i, M) scanf("%d %d", &BC[i].first, &BC[i].second);

  sort(A.begin(), A.end());
  sort(BC.begin(), BC.end(), [](auto const& x, auto const& y){
    return x.second >= y.second;
  });

  int edited = 0;
  ll ans = 0;
  rep(i, M) {
    int b = BC[i].first, c = BC[i].second;
    int last = std::lower_bound(A.begin() + edited, A.end(), c) - A.begin();
    int distance = min((long)b, last - edited);
    ans += (ll)distance * c;
    edited += distance;
    if (edited >= N) { break; }
  }
  REP(i, edited, N) ans += A[i];
  cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:40:23: error: no matching function for call to 'min(long int, int)'
   40 |     int distance = min((long)b, last - edited);
      |                    ~~~^~~~~~~~~~~~~~~~~~~~~~~~
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:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:40:23: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'int')
   40 |     int distance = min((long)b, last - edited);
      |                    ~~~^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281: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:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:40:23: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   40 |     int distance = min((long)b, last - edited);
      |                    ~~~^~~~~~~~~~~~~~~~~~~~~~~~