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
50
51
52
53
54
55
56
#include <iostream>
#define N_MAX 500001
#define INF 1000000000

using namespace std;

int n,m;
int a[N_MAX], a_min = INF, num_min;
//long long d[N_MAX], b[N_MAX];
long long d, b;
long long pole[N_MAX];
int current_day = 0;

long long zniwa_dzis;

int main()
{
    ios_base::sync_with_stdio(false);

    cin >> n >> m;

    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
        if (a[i] < a_min)
        {
            a_min = a[i];
            num_min = i;
        }
    }

    for (int i = 0; i < m; ++i)
    {
        zniwa_dzis = 0;
        cin >> d >> b;

        for (; current_day < d; ++current_day) // symulacja czasu
        {
            for (int j = 0; j < n; ++j)
            {
                pole[j] += a[j];
            }
        }
        for (int j = 0; j < n; ++j) // zniwa
        {
            if (pole[j] > b)
            {
                zniwa_dzis += pole[j] - b;
                pole[j] = b;
            }
        }
        cout << zniwa_dzis << "\n";
    }

    return 0;
}