#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
int n, q;
long long X[MAXN], W[MAXN], Min[MAXN], Max[MAXN], L[MAXN], R[MAXN];
vector <long long> V;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> q;
for(int i = 0; i < n; i++)
{
cin >> X[i];
}
for(int i = 0; i < q; i++)
{
cin >> W[i];
if(i == 0)
{
Min[i] = min(Min[i], W[i]);
Max[i] = max(Max[i], W[i]);
}
else
{
W[i] += W[i - 1];
Min[i] = min(Min[i - 1], W[i]);
Max[i] = max(Max[i - 1], W[i]);
}
V.push_back(Max[i] - Min[i]);
}
for(int i = 0; i < n; i++)
{
L[i] = X[i] + Min[q - 1];
R[i] = X[i] + Max[q - 1];
}
for(int i = 0; i + 1 < n; i++)
{
int id = lower_bound(V.begin(), V.end(), X[i + 1] - X[i]) - V.begin();
if(id == q)
{
continue;
}
long long tmp = W[id] - (id == 0 ? 0 : W[id - 1]);
if(tmp > 0)
{
R[i] = X[i + 1] + Min[id];
L[i + 1] = X[i + 1] + Min[id];
}
else
{
R[i] = X[i] + Max[id];
L[i + 1] = X[i] + Max[id];
}
}
for(int i = 0; i < n; i++)
{
cout << R[i] - L[i] << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
2 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
320 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
2 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
320 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
31 ms |
8764 KB |
Output is correct |
21 |
Correct |
28 ms |
8588 KB |
Output is correct |
22 |
Correct |
28 ms |
8380 KB |
Output is correct |
23 |
Correct |
27 ms |
8376 KB |
Output is correct |
24 |
Correct |
36 ms |
8920 KB |
Output is correct |
25 |
Correct |
112 ms |
16768 KB |
Output is correct |
26 |
Correct |
108 ms |
16604 KB |
Output is correct |
27 |
Correct |
103 ms |
16232 KB |
Output is correct |
28 |
Correct |
102 ms |
16408 KB |
Output is correct |
29 |
Correct |
105 ms |
15872 KB |
Output is correct |
30 |
Correct |
92 ms |
15260 KB |
Output is correct |
31 |
Correct |
67 ms |
14772 KB |
Output is correct |
32 |
Correct |
67 ms |
14880 KB |
Output is correct |
33 |
Correct |
10 ms |
2128 KB |
Output is correct |
34 |
Correct |
107 ms |
17084 KB |
Output is correct |
35 |
Correct |
102 ms |
16376 KB |
Output is correct |
36 |
Correct |
101 ms |
16656 KB |
Output is correct |
37 |
Correct |
105 ms |
16456 KB |
Output is correct |
38 |
Correct |
100 ms |
16296 KB |
Output is correct |
39 |
Correct |
108 ms |
16412 KB |
Output is correct |
40 |
Correct |
75 ms |
16492 KB |
Output is correct |
41 |
Correct |
32 ms |
9344 KB |
Output is correct |
42 |
Correct |
60 ms |
14856 KB |
Output is correct |
43 |
Correct |
93 ms |
18260 KB |
Output is correct |
44 |
Correct |
35 ms |
9252 KB |
Output is correct |
45 |
Correct |
69 ms |
16388 KB |
Output is correct |
46 |
Correct |
82 ms |
18348 KB |
Output is correct |
47 |
Correct |
90 ms |
18488 KB |
Output is correct |
48 |
Correct |
83 ms |
18632 KB |
Output is correct |