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

using namespace std;

int main()
{
    long n, m;
    cin>>n>>m;
    vector< long > growingHeight(n);
    vector< long > currentHeight(n);

    long temp;
    for(long i=0;i<n;i++)
    {
        cin>>growingHeight[i];
        currentHeight[i] = 0;
    }
    long lastDay = 0;
    long cuttingHeight;
    long dayDelta;
    long long sum;
    for(long i=0;i<m;i++)
    {
        sum=0;

        cin>>temp;
        dayDelta=temp-lastDay;
        lastDay=temp;

        cin>>cuttingHeight;
        for(long l=0;l<n;l++)
        {
            temp = currentHeight[l];
            temp+=dayDelta*growingHeight[l];
            if(temp > cuttingHeight)
            {
                sum+=temp-cuttingHeight;
                temp=cuttingHeight;
            }
            currentHeight[l]=temp;
        }
        cout<<sum<<endl;
    }
    return 0;
}