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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//Beniamin Gajecki
#include <iostream>
#include <cmath>
#include <vector>

int getTime(std::vector<int>& _a, int _b)
{
    int x = 0, t = 0;
    for(unsigned i = 0; i<_a.size(); ++i)
    {
        if(i == 0)
        {
            if(_b - _a[i] > 0)
            {
                x += _b - _a[i];
                t += x;
            }
        }
        else
        {
            if(_b > _a[i] - _a[i - 1])
                x += (_b - (_a[i] - _a[i - 1])) + t;

            if(t > _a[i] - _a[i - 1])
                t += _b - (_a[i] - _a[i - 1]);
            else
                t = 0;
        }
    }
    return x;
}

int main()
{
    int n, m;
    std::cin>>n>>m;
    if((1 <= n) && (m <= 200000))
    {
        std::vector<int> customer;
        std::vector<unsigned> oven;
        unsigned x;
        for(unsigned i = 0; i<n; ++i)
        {
            std::cin>>x;
            if(i == 0)
            {
                if((0 <= x) && (x <= pow(10, 12)))
                    customer.push_back(x);
                else
                    return 1;
            }
            else
            {
                if((0 <= x) && (customer[i - 1] <= x) && (x <= pow(10, 12)))
                    customer.push_back(x);
                else
                    return 1;
            }
        }
        for(unsigned i = 0; i<m; ++i)
        {
            std::cin>>x;
            if((1 <= x) && (x <= pow(10, 6)))
                oven.push_back(x);
            else
                return 1;
        }
        for(unsigned i = 0; i<m - 1; ++i)
            std::cout<<getTime(customer, oven[i])<<std::endl;
        std::cout<<getTime(customer, oven[m - 1]);
        return 0;
    }
    return 1;
}