Language: C++


int ctoi(char c) {
	switch (c) {
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return 0;
	}
}
using namespace std;
typedef long long ll;
//定義場所//
ll i, j, k, l, m, n;
ll N, M, K;
ll MOD = 1000000007;
ll ans = 0;
////////////

bool pairCompare(const pair<ll,ll> firstElof, pair<ll,ll> secondElof)
{
	return firstElof.second > secondElof.second;
}

int main()
{
	cin >> N >> M;
	vector<ll> A;
	vector<pair<ll, ll> >BC(M);
	ll ans = 0;
	for (i = 0; i < N; i++) {
		ll a;
		cin >> a;
		A.push_back(a);
	}
	sort(A.begin(), A.end());
	for (i = 0; i < M; i++) {
		int b, c;
		cin >> b >> c;
		BC[i] = make_pair(b, c);
	}
	sort(BC.begin(), BC.end(),pairCompare);
	//reverse(BC.begin(), BC.end());
	int depth = 0;
	int count = 0;
	for (i = 0; i < N; i++) {
		if (A[i] < BC[depth].second) {
			A[i] = BC[depth].second;
			count++;
		}
		else {
			break;
		}
		if (count >= BC[depth].first) {
			depth++;
			count = 0;
			if (depth > M - 1) {
				break;
			}
		}
	}
	for (i = 0; i < N; i++) {
		ans += A[i];
	}

	cout << ans;

}

Compiler output:
a.cc:26:24: error: 'pair' does not name a type
   26 | bool pairCompare(const pair<ll,ll> firstElof, pair<ll,ll> secondElof)
      |                        ^~~~
a.cc:26:28: error: expected ',' or '...' before '<' token
   26 | bool pairCompare(const pair<ll,ll> firstElof, pair<ll,ll> secondElof)
      |                            ^
a.cc: In function 'bool pairCompare(int)':
a.cc:28:16: error: 'firstElof' was not declared in this scope
   28 |         return firstElof.second > secondElof.second;
      |                ^~~~~~~~~
a.cc:28:35: error: 'secondElof' was not declared in this scope
   28 |         return firstElof.second > secondElof.second;
      |                                   ^~~~~~~~~~
a.cc: In function 'int main()':
a.cc:33:9: error: 'cin' was not declared in this scope
   33 |         cin >> N >> M;
      |         ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | 
a.cc:34:9: error: 'vector' was not declared in this scope
   34 |         vector<ll> A;
      |         ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | 
a.cc:34:18: error: expected primary-expression before '>' token
   34 |         vector<ll> A;
      |                  ^
a.cc:34:20: error: 'A' was not declared in this scope
   34 |         vector<ll> A;
      |                    ^
a.cc:35:16: error: 'pair' was not declared in this scope
   35 |         vector<pair<ll, ll> >BC(M);
      |                ^~~~
a.cc:1:1: note: 'std::pair' is defined in header '<utility>'; this is probably fixable by adding '#include <utility>'
  +++ |+#include <utility>
    1 | 
a.cc:35:23: error: expected primary-expression before ',' token
   35 |         vector<pair<ll, ll> >BC(M);
      |                       ^
a.cc:35:27: error: expected primary-expression before '>' token
   35 |         vector<pair<ll, ll> >BC(M);
      |                           ^
a.cc:35:29: error: expected primary-expression before '>' token
   35 |         vector<pair<ll, ll> >BC(M);
      |                             ^
a.cc:35:30: error: 'BC' was not declared in this scope
   35 |         vector<pair<ll, ll> >BC(M);
      |                              ^~
a.cc:42:9: error: 'sort' was not declared in this scope; did you mean 'short'?
   42 |         sort(A.begin(), A.end());
      |         ^~~~
      |         short
a.cc:46:25: error: 'make_pair' was not declared in this scope
   46 |                 BC[i] = make_pair(b, c);
      |                         ^~~~~~~~~
a.cc:46:25: note: 'std::make_pair' is defined in header '<utility>'; this is probably fixable by adding '#include <utility>'
a.cc:72:9: error: 'cout' was not declared in this scope
   72 |         cout << ans;
      |         ^~~~
a.cc:72:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'