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

using namespace std;

int main()
{
    long long clientTime[200000];
    long long i,d,n,m,j,sum,res;
    cin >> n;
    cin >> m;

    for (i=0;i<n;i++)
    {
        cin >> clientTime[i];
    }
    for(i=(n-1);i>0;i--)
    {
        clientTime[i] = clientTime[i] - clientTime[i-1];
    }
    
    for (i=0;i<m;i++)
    {
        cin >> d;
        res = 0;
        sum = 0;
        for(j=0;j<n;j++)
        {
            res = clientTime[j] - d + res;
            if (res > 0)
                res = 0;
            else
                sum -= res;
        }
        cout << sum << endl; 
    }
    return 0;
}