Language: C++

#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL N, M;
	in >> N >> M;
	std::vector<LL>A(N), B(M), C(M);
	rep(i, N) in >> A[i];
	rep(i, M) in >> B[i] >> C[i];

	std::vector<std::pair<LL, LL>>ope;
	rep(i, M) ope.push_back(std::make_pair(C[i], B[i]));
	ope.push_back(std::make_pair(0, 114514));
	std::sort(A.begin(), A.end());
	std::sort(ope.rbegin(), ope.rend());

	LL ans = 0, seek = 0;
	rep(i, N)
	{
		auto it = std::lower_bound(A.begin() + i, A.end(), ope[seek].first);
		LL cnt = std::min(it - (A.begin() + i), ope[seek].second);
		ans += ope[seek].first * cnt;
		ope[seek].second -= cnt;
		if (ope[seek].second == 0) ++seek;
		if (cnt == 0) ans += A[i];
		else i += cnt - 1;
	}

	out << ans << std::endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:25:34: error: no matching function for call to 'min(__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type, long long int&)'
   25 |                 LL cnt = std::min(it - (A.begin() + i), ope[seek].second);
      |                          ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:25:34: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
   25 |                 LL cnt = std::min(it - (A.begin() + i), ope[seek].second);
      |                          ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:25:34: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   25 |                 LL cnt = std::min(it - (A.begin() + i), ope[seek].second);
      |                          ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~