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
49
#include <cstdio>
#include <algorithm>
using namespace std;

typedef unsigned long long int llu;

int area, num_of_mowing, x;
int * grass_grows;
llu * mowing_days;
llu * mowing_heights;
llu * grass_heights;
llu y, z, last_day, weight;

int main() {
    last_day = 0;
    scanf("%d %d", &area, &num_of_mowing);
    grass_grows = new int[area];
    grass_heights = new llu[area];
    for (int i = 0; i < area; ++i){
        scanf("%d", &x);
        grass_grows[i] = x;
        grass_heights[i] = 0;
    }
    mowing_days = new llu[num_of_mowing];
    mowing_heights = new llu[num_of_mowing];

    for (int i = 0; i < num_of_mowing; ++i){
        scanf("%llu %llu", &y, &z);
        mowing_days[i] = y - last_day;
        last_day = y;
        mowing_heights[i] = z;
    }
    for (int i = 0; i < num_of_mowing; ++i)
    {
        weight = 0;
        for (int j = 0; j < area; ++j)
        {
            z = grass_heights[j] + (mowing_days[i] * grass_grows[j]);
            if (z > mowing_heights[i]){
                weight = weight + z - mowing_heights[i];
                grass_heights[j] = mowing_heights[i];
            } else  {
                grass_heights[j] = z;
            }
        }
        printf("%llu\n", weight);
    }
    return 0;
}