#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define dbg(x) cerr << #x << ": " << x << endl;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, q;
cin >> n >> q;
vector<ll> a(n);
for (auto& x : a) {
cin >> x;
}
ll max_value = 0;
ll min_value = 0;
ll curr_value = 0;
vector<ll> ans(n);
set<pair<ll, int>> distances;
for (int i = 0; i < n - 1; ++i) {
distances.emplace(a[i + 1] - a[i], i);
}
ll left_add = 0;
ll right_add = 0;
while (q--) {
ll w;
cin >> w;
curr_value += w;
if (w > 0) {
if (curr_value <= max_value) continue;
ll d = curr_value - max_value;
max_value = max(max_value, curr_value);
ans[n - 1] += d;
while (!distances.empty()) {
auto [value, idx] = *distances.begin();
if (value - left_add - right_add > d) break;
ans[idx] += left_add + value - left_add - right_add;
ans[idx + 1] += right_add;
distances.erase(*distances.begin());
}
left_add += d;
} else {
if (curr_value >= min_value) continue;
ll d = min_value - curr_value;
min_value = min(min_value, curr_value);
ans[0] += d;
while (!distances.empty()) {
auto [value, idx] = *distances.begin();
if (value - left_add - right_add > d) break;
ans[idx + 1] += right_add + value - left_add - right_add;
ans[idx] += left_add;
distances.erase(*distances.begin());
}
right_add += d;
}
}
for (const auto& [value, idx] : distances) {
ans[idx] += left_add;
ans[idx + 1] += right_add;
}
for (auto x : ans) {
cout << x << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
24 ms |
212 KB |
Output is correct |
21 |
Correct |
23 ms |
212 KB |
Output is correct |
22 |
Correct |
22 ms |
332 KB |
Output is correct |
23 |
Correct |
21 ms |
468 KB |
Output is correct |
24 |
Correct |
30 ms |
2784 KB |
Output is correct |
25 |
Correct |
160 ms |
21300 KB |
Output is correct |
26 |
Correct |
159 ms |
21208 KB |
Output is correct |
27 |
Correct |
151 ms |
20808 KB |
Output is correct |
28 |
Correct |
161 ms |
21076 KB |
Output is correct |
29 |
Correct |
150 ms |
20528 KB |
Output is correct |
30 |
Correct |
139 ms |
19900 KB |
Output is correct |
31 |
Correct |
101 ms |
19344 KB |
Output is correct |
32 |
Correct |
117 ms |
19512 KB |
Output is correct |
33 |
Correct |
13 ms |
2416 KB |
Output is correct |
34 |
Correct |
153 ms |
21584 KB |
Output is correct |
35 |
Correct |
154 ms |
20960 KB |
Output is correct |
36 |
Correct |
165 ms |
21208 KB |
Output is correct |
37 |
Correct |
157 ms |
20936 KB |
Output is correct |
38 |
Correct |
159 ms |
20816 KB |
Output is correct |
39 |
Correct |
152 ms |
21144 KB |
Output is correct |
40 |
Correct |
113 ms |
21068 KB |
Output is correct |
41 |
Correct |
28 ms |
2976 KB |
Output is correct |
42 |
Correct |
186 ms |
19544 KB |
Output is correct |
43 |
Correct |
137 ms |
22876 KB |
Output is correct |
44 |
Correct |
31 ms |
2852 KB |
Output is correct |
45 |
Correct |
195 ms |
20968 KB |
Output is correct |
46 |
Correct |
132 ms |
22856 KB |
Output is correct |
47 |
Correct |
133 ms |
23252 KB |
Output is correct |
48 |
Correct |
135 ms |
23136 KB |
Output is correct |