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
#include<bits/stdc++.h>
using namespace std;
int pole [50000];
int wzor [50000];
int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &wzor [i]);
    }
    int a, b, day = 0, wynik = 0;
    for (int i = 0; i < m; i++)
    {
        scanf("%d%d", &a, &b);
        for (int w = 0; w < a - day; w++)
            for (int j = 0; j < n; j++)
                pole[j]+=wzor[j];
        day = a;
        for (int w = 0; w < n; w++)
        {
            if (pole [w] > b)
            {
                wynik = wynik + pole[w] - b;
                pole[w] = b;
            }
        }
        printf("%d\n", wynik);
        wynik = 0;
    }
    return 0;
}