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

using namespace std;

int main ()
{
    ios_base::sync_with_stdio(false);
    vector <long long> suma;
    vector <int> dane;
    int a,b,c;
    long long d;
    cin >> a >> b;
    for(int i=0;i<a;i++)
    {
        cin >> c;
        dane.push_back(c);
        suma.push_back(0);
    }
    long long wartosc;
    for(int i=0;i<b;i++)
    {
        wartosc=0;
        cin >> d >> d;
        for(int j=0;j<a;j++)
        {
            suma[j]+=dane[j];
            if(suma[j]>d)
            {
                long long tmp=suma[j]-d;
                wartosc+=tmp;
                suma[j]=d;
            }
        }
        cout << wartosc << "\n";
    }

    return 0;
}