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
#include <iostream>
using namespace std;

int main() {
	int n, m, d, b,t;
	unsigned long long sum=0;
	unsigned long long ilesiana=0;
	scanf("%d %d",&n,&m);
	
	for(int i=0;i<n;i++)
	{
		scanf("%d",&t);
		sum += t;
	}	
	
	for(int i=0;i<m;i++)
		{
			scanf("%d %d", &d, &b);
			if(sum*(unsigned long long)d - ilesiana >= (unsigned long long)b*(unsigned long long)n)
				{
				cout << sum*(unsigned long long)d-(unsigned long long)b*(unsigned long long)n - ilesiana <<endl;
				ilesiana += sum*(unsigned long long)d-(unsigned long long)b*(unsigned long long)n - ilesiana;
				}
			else
				cout << 0 << endl;
			
		}
		
	return 0;
}