1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <cstdio>
#include <unordered_map>
using namespace std;
typedef tuple<int,int,long long> para;
typedef unordered_map<int,para> mapa;

mapa t;
int n,m,x,last=0,tmpa,tmpb;
unsigned long long suma,a,b,dif;
int main() {
	scanf("%d %d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%d",&x);
		get<0>(t[x])=x;
		get<1>(t[x])++;
		get<2>(t[x])=0;
	}


	for(int i=0;i<m;i++){
		scanf("%llu %llu",&a,&b);
		suma=0;
		dif=a-last;
		last=a;
		for ( auto it = t.begin(); it != t.end(); ++it ){
			tmpa=get<0>(it->second);
			get<2>(it->second)+=(tmpa*dif);
			if(get<2>(it->second)>b){
				suma+=(get<2>(it->second)-b)*get<1>(it->second);
				get<2>(it->second)=b;
			}
		}
		printf("%llu\n",suma);
	}

	return 0;
}