#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
#include <set>
typedef long long llong;
const int MAXN = 200000 + 10;
const int INF = 1e9;
int n, m;
llong a[MAXN];
llong b[MAXN];
llong min[MAXN];
llong max[MAXN];
llong l[MAXN];
llong r[MAXN];
void solve()
{
llong sum = 0;
for (int i = 1 ; i <= m ; ++i)
{
sum += b[i];
min[i] = std::min(min[i - 1], sum);
max[i] = std::max(max[i - 1], sum);
}
l[1] = a[1] + min[m];
r[n] = a[n] + max[m];
for (int i = 1 ; i < n ; ++i)
{
int ll = 0, rr = m + 1, mid;
while (ll < rr - 1)
{
mid = (ll + rr) / 2;
if (a[i] + max[mid] <= a[i + 1] + min[mid]) ll = mid;
else rr = mid;
}
r[i] = a[i] + max[ll];
l[i + 1] = a[i + 1] + min[ll];
if (rr <= m)
{
if (b[rr] < 0) l[i + 1] = r[i];
else r[i] = l[i + 1];
}
}
for (int i = 1 ; i <= n ; ++i)
{
std::cout << r[i] - l[i] << '\n';
}
}
void input()
{
std::cin >> n >> m;
for (int i = 1 ; i <= n ; ++i)
{
std::cin >> a[i];
}
for (int i = 1 ; i <= m ; ++i)
{
std::cin >> b[i];
}
}
void fastIOI()
{
std::ios_base :: sync_with_stdio(0);
std::cout.tie(nullptr);
std::cin.tie(nullptr);
}
int main()
{
fastIOI();
input();
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
2 ms |
6492 KB |
Output is correct |
3 |
Correct |
2 ms |
6492 KB |
Output is correct |
4 |
Correct |
2 ms |
6492 KB |
Output is correct |
5 |
Correct |
2 ms |
6492 KB |
Output is correct |
6 |
Correct |
2 ms |
6492 KB |
Output is correct |
7 |
Correct |
2 ms |
6492 KB |
Output is correct |
8 |
Correct |
2 ms |
6492 KB |
Output is correct |
9 |
Correct |
2 ms |
6492 KB |
Output is correct |
10 |
Correct |
2 ms |
6492 KB |
Output is correct |
11 |
Correct |
2 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
2 ms |
6492 KB |
Output is correct |
15 |
Correct |
2 ms |
6492 KB |
Output is correct |
16 |
Correct |
2 ms |
6492 KB |
Output is correct |
17 |
Correct |
2 ms |
6492 KB |
Output is correct |
18 |
Correct |
2 ms |
6748 KB |
Output is correct |
19 |
Correct |
2 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Correct |
2 ms |
6492 KB |
Output is correct |
3 |
Correct |
2 ms |
6492 KB |
Output is correct |
4 |
Correct |
2 ms |
6492 KB |
Output is correct |
5 |
Correct |
2 ms |
6492 KB |
Output is correct |
6 |
Correct |
2 ms |
6492 KB |
Output is correct |
7 |
Correct |
2 ms |
6492 KB |
Output is correct |
8 |
Correct |
2 ms |
6492 KB |
Output is correct |
9 |
Correct |
2 ms |
6492 KB |
Output is correct |
10 |
Correct |
2 ms |
6492 KB |
Output is correct |
11 |
Correct |
2 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
2 ms |
6492 KB |
Output is correct |
15 |
Correct |
2 ms |
6492 KB |
Output is correct |
16 |
Correct |
2 ms |
6492 KB |
Output is correct |
17 |
Correct |
2 ms |
6492 KB |
Output is correct |
18 |
Correct |
2 ms |
6748 KB |
Output is correct |
19 |
Correct |
2 ms |
6492 KB |
Output is correct |
20 |
Correct |
20 ms |
9812 KB |
Output is correct |
21 |
Correct |
20 ms |
9556 KB |
Output is correct |
22 |
Correct |
18 ms |
9308 KB |
Output is correct |
23 |
Correct |
17 ms |
9308 KB |
Output is correct |
24 |
Correct |
22 ms |
9808 KB |
Output is correct |
25 |
Correct |
78 ms |
14932 KB |
Output is correct |
26 |
Correct |
77 ms |
14932 KB |
Output is correct |
27 |
Correct |
79 ms |
14676 KB |
Output is correct |
28 |
Correct |
77 ms |
14680 KB |
Output is correct |
29 |
Correct |
77 ms |
14248 KB |
Output is correct |
30 |
Correct |
71 ms |
13652 KB |
Output is correct |
31 |
Correct |
49 ms |
13140 KB |
Output is correct |
32 |
Correct |
48 ms |
13140 KB |
Output is correct |
33 |
Correct |
8 ms |
7768 KB |
Output is correct |
34 |
Correct |
84 ms |
15384 KB |
Output is correct |
35 |
Correct |
81 ms |
15188 KB |
Output is correct |
36 |
Correct |
83 ms |
14932 KB |
Output is correct |
37 |
Correct |
87 ms |
14932 KB |
Output is correct |
38 |
Correct |
76 ms |
14676 KB |
Output is correct |
39 |
Correct |
78 ms |
14932 KB |
Output is correct |
40 |
Correct |
54 ms |
14880 KB |
Output is correct |
41 |
Correct |
21 ms |
10324 KB |
Output is correct |
42 |
Correct |
47 ms |
13232 KB |
Output is correct |
43 |
Correct |
59 ms |
16468 KB |
Output is correct |
44 |
Correct |
20 ms |
10324 KB |
Output is correct |
45 |
Correct |
51 ms |
14836 KB |
Output is correct |
46 |
Correct |
57 ms |
16724 KB |
Output is correct |
47 |
Correct |
69 ms |
16980 KB |
Output is correct |
48 |
Correct |
60 ms |
16980 KB |
Output is correct |