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
39
40
41
42
43
44
45
46
47
48
#include <iostream>
using namespace std;

int main(void)
{
    int n, m;
    cin>>n>>m;
    int d, b;
    int *suma=new int[m];
    long long *trawa=new long long[n];
    int *szybkosc=new int[n];
    long long dn=1;
    
    for(int i=0; i<n; i++)
    {
        cin>>b;
        trawa[i]=b;
        szybkosc[i]=b;
    }

    
    for (int i=0; i<m; i++)
    {
        suma[i]=0;
        cin>>d>>b;
        for (int j=0; j<n; j++)
        {
            trawa[j]=trawa[j]+szybkosc[j]*(d-dn);
            if(trawa[j]>=b)
            {
                suma[i]=suma[i]+trawa[j]-b;
                trawa[j]=b;
            }
        }
        dn=d;
    }
    
    for (int i=0; i<m; i++)
    {
        cout<<suma[i]<<endl;
    }
    
    
    delete [] szybkosc;
    delete [] trawa;
    delete [] suma;
    return 0;
}