Language: C++

#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<bitset>
#include<utility>
using namespace std;


#define MP make_pair

int main(void) {

	long long n,m,a[100000],b[100000],c[100000],sum[100000]={};

	vector<pair<(long long),(long long)>> bc(100000);

	cin>>n>>m;
	for (int i = 0; i < n; i++) {
		cin>>a[i];
	}

	for (int i = 0; i < m; i++) {
		cin>>b[i]>>c[i];
		bc[i]=MP(c[i],b[i]);
	}

	sort(a,a+n);

	for (int i = 0; i < n; i++) {
		sum[i]=a[i];
		if(i!=0)sum[i]+=sum[i-1];
	}

	sort(bc.begin(),bc.begin()+m,greater<pair<(long long),(long long)>>());

	/*for (int i = 0; i < m; i++) {
		cout<<bc[i].first<<"  "<<bc[i].second<<"\n";
	}*/

	long long ser1,serfir,serend,tmp=0,ans=0;


	for (int ser = 0; ser < m; ser++) {
		ser1=bc[ser].first;
		serfir=a[tmp];
		serend=a[tmp+(bc[ser].second)-1];


	//	printf("%d %d %d\n",ser1,serfir,serend);

		if(ser1>=serend){
			ans+=ser1*(bc[ser].second);
			tmp+=bc[ser].second;
		}else{
			for (int i = tmp; i <= tmp+(bc[ser].second)-1; i++) {
				if(ser1>=a[i]){
					ans+=ser1;
				}else{
					ans+=a[i];
				}
			}
			//printf("ser=%d,ans=%d\n",ser,ans);
			ans+=sum[n-1]-sum[tmp+(bc[ser].second)-1];
			//cout<<sum[n-1]<<" "<<sum[tmp+(bc[ser].second)-1]<<"\n";
			//printf("ser=%d,ans=%d\n",ser,ans);

			break;
		}

	//	printf("ser=%d,ans=%d\n",ser,ans);

	}


	cout<<ans<<"\n";










	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:19:27: error: wrong number of template arguments (1, should be 2)
   19 |         vector<pair<(long long),(long long)>> bc(100000);
      |                           ^~~~
In file included from /usr/include/c++/14/string:48,
                 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:2:
/usr/include/c++/14/bits/stl_iterator.h:3013:12: note: provided for 'template<class _T1, class _T2> struct std::pair'
 3013 |     struct pair;
      |            ^~~~
a.cc:19:16: error: template argument 1 is invalid
   19 |         vector<pair<(long long),(long long)>> bc(100000);
      |                ^~~~~~~~~~~~~~~
a.cc:19:16: error: template argument 2 is invalid
a.cc:19:31: error: expected unqualified-id before ')' token
   19 |         vector<pair<(long long),(long long)>> bc(100000);
      |                               ^
a.cc:28:17: error: 'bc' was not declared in this scope; did you mean 'c'?
   28 |                 bc[i]=MP(c[i],b[i]);
      |                 ^~
      |                 c
a.cc:38:14: error: 'bc' was not declared in this scope; did you mean 'c'?
   38 |         sort(bc.begin(),bc.begin()+m,greater<pair<(long long),(long long)>>());
      |              ^~
      |              c
a.cc:38:57: error: wrong number of template arguments (1, should be 2)
   38 |         sort(bc.begin(),bc.begin()+m,greater<pair<(long long),(long long)>>());
      |                                                         ^~~~
/usr/include/c++/14/bits/stl_iterator.h:3013:12: note: provided for 'template<class _T1, class _T2> struct std::pair'
 3013 |     struct pair;
      |            ^~~~
a.cc:38:46: error: template argument 1 is invalid
   38 |         sort(bc.begin(),bc.begin()+m,greater<pair<(long long),(long long)>>());
      |                                              ^~~~~~~~~~~~~~~
a.cc:38:64: error: expected primary-expression before 'long'
   38 |         sort(bc.begin(),bc.begin()+m,greater<pair<(long long),(long long)>>());
      |                                                                ^~~~
a.cc:38:64: error: expected ')' before 'long'
   38 |         sort(bc.begin(),bc.begin()+m,greater<pair<(long long),(long long)>>());
      |                                                               ~^~~~
      |                                                                )