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
#include <iostream>
using namespace std;
long long tab[500007];
int tab2[500007];
int main()
{
    ios_base::sync_with_stdio(false);
    int n,m;
    long long pom=0;
    long long d,b;
    long long x=0;
    cin >> n >> m;
    for(int i=0;i<n;i++)
        cin >> tab2[i];
    cin >> d >> b;
    for(int j=0;j<n;j++)
    {
        tab[j]+=(d-x)*tab2[j];
        if(tab[j]>b)
        {
            pom+=tab[j]-b;
            tab[j]=b;
        }
    }
    x=d;
    cout << pom << endl;
    for(int i=1;i<m;i++)
    {
        pom=0;
        cin >> d >> b;
        for(int j=0;j<n;j++)
        {
            tab[j]+=(d-x)*tab2[j];
            if(tab[j]>b)
            {
                pom+=tab[j]-b;
                tab[j]=b;
            }
        }
        cout << pom << endl;
        x=d;
    }
    return 0;
}