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
#include <iostream>

using namespace std;

int main()
{
    int n, m, *a, *pom;
    long long d, b, k = 0;
    unsigned long long suma = 0, wynik = 0;
    cin >> n >> m;

    a = new int[n];
    pom = new int[n];

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


    for(int i = 0; i < m; i++)
    {
        wynik = 0;
        cin >> d >> b;
        k = d - k;

        for(int i = 0; i < n; i++)
        {
            pom[i] += k*a[i];
            if(pom[i] > b)
            {
                wynik += pom[i]-b;
                pom[i] = b;
            }
        }

        cout << wynik << endl;
        k = d;
    }

}