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
57
58
59
60
#include<bits/stdc++.h>
#define ll long long int
using namespace std;

const int N = 1000005;
ll l[N];
ll p[N];
ll czas;
ll koniec;
ll n, m, wyn, pom;

int main()
{
    scanf("%lld %lld", &n, &m);

    for(int i =0 ;i < n; ++i)
    {
        scanf("%lld",&l[i]);
    }

    for(int i = 0; i < m ; ++i)
    {
        scanf("%lld", &p[i]);
    }

    for(int i = 0; i < m ; ++i)
    {
        czas = p[i];
        wyn = 0;
        koniec = 0;

        for(int j = 0; j < n; ++j)
        {
            if(koniec >= l[j])
            {
                wyn += (koniec - l[j]);
                wyn += czas;
                koniec += czas;
            }
            else
            {
                pom = l[j] - koniec;
                if(pom < czas)
                {
                    pom = czas - pom;
                    koniec = l[j] + pom;
                    wyn += pom;
                }
                else
                {
                    koniec = l[j];
                }
            }
        }

        printf("%lld\n", wyn);
    }

return 0;
}