Language: C++

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

using namespace std;
typedef long long ll;

ll find_boundary(vector<ll> &A, ll x, ll N){
  ll p = A.size() / 2;
  ll p_prev = N, p_prev2 = N, tmp;
  
  while (1){
    if (A[p] > x){
      p_prev2 = p_prev;
      tmp = p;
      p -= (abs(p_prev - p)) / 2;
      p = max(p, 0);
      p_prev = tmp;
    }
    else if (A[p] < x){
      p_prev2 = p_prev;
      tmp = p;
      p += (abs(p_prev - p)) / 2;
      p = min(A.size() - 1, p);
      p_prev = tmp;
    }
    if (p_prev2 == p || A[p] == x) break;
  }
  if (A[p] == x) return p;
  else if (A[p] > x) return p - 1;
  else return p + 1;
}

bool comp (const vector<ll> &a, const vector<ll> &b){
  return a[1] > b[1];
}
    

int main(){
  int N, M;
  cin >> N >> M;
  ll tmp, b, c, p;
  vector<ll> A;
  vector<vector<ll>> move;
  for (int i=0; i<N; i++){
    cin >> tmp;
    A.push_back(tmp);
  }
  sort(A.begin(), A.end());
  ll Bmax = -1, Cmax = -1;
  for (int i=0; i<M; i++){
    cin >> b >> c;
    move.emplace_back(vector<ll>({b, c}));
  }
  sort(move.begin(), move.end(), comp);
  ll replaced = 0;
  vector<vector<ll>> pickup;
  for (auto e : move){
    p = min(find_boundary(A, e[1], N), e[0]);
    if (p >= 0){
      replaced += p;
      pickup.emplace_back(vector<ll>({p, e[1]}));
      A.erase(A.begin(), A.begin() + p);
    }
    else break;
  }
  ll ans = 0;
  for (auto e : pickup){
    ans += e[0]*e[1];
  }
  for (ll i=0; i<A.size(); i++){
    ans += A[i];
  }
  cout << ans << endl;
                          
  return 0;
}

Compiler output:
a.cc: In function 'll find_boundary(std::vector<long long int>&, ll, ll)':
a.cc:17:14: error: no matching function for call to 'max(ll&, int)'
   17 |       p = max(p, 0);
      |           ~~~^~~~~~
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: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:17:14: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   17 |       p = max(p, 0);
      |           ~~~^~~~~~
/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:3:
/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:17:14: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   17 |       p = max(p, 0);
      |           ~~~^~~~~~
a.cc:24:14: error: no matching function for call to 'min(std::vector<long long int>::size_type, ll&)'
   24 |       p = min(A.size() - 1, p);
      |           ~~~^~~~~~~~~~~~~~~~~
/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:24:14: note:   deduced conflicting types for parameter 'const _Tp' ('long unsigned int' and 'll' {aka 'long long int'})
   24 |       p = min(A.size() - 1, p);
      |           ~~~^~~~~~~~~~~~~~~~~
/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
/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:24:14: note:   mismatched types 'std::initializer_list<_Tp>' and 'long unsigned int'
   24 |       p = min(A.size() - 1, p);
      |           ~~~^~~~~~~~~~~~~~~~~