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 <stdio.h>
#include <stdlib.h>

int main()
{
    unsigned int n,m;
    scanf("%d %d", &n,&m);
    unsigned int *grow_rate;
    grow_rate = malloc(sizeof(int)*n);
    long long int *field = calloc(n,sizeof(long long int));
    long long int *results = malloc(sizeof(long long int) *m);
    int i,j;
    for(i=0; i< n; ++i) {
        scanf("%d",grow_rate + i);
    }

    long long old_day, current_day, cut_height, sum;

    int diff;
    old_day=0;



    for(i=0; i<m; ++i) {
        scanf("%lld %lld", &current_day, &cut_height);
        diff =  current_day - old_day;
        old_day = current_day;
        sum=0;
        for(j=0; j<n; ++j) {
            field[j] += grow_rate[j]*diff;
            if(field[j] > cut_height ) {
                sum+= field[j] - cut_height;
                field[j] = cut_height;
            }
        }
        results[i] = sum;
    }

    for(i =0 ; i<m; ++i) {
        printf("%d\n",results[i]);
    }



    return 0;
}