#include <bits/stdc++.h>
using namespace std;
template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl
using ll = long long;
const ll inf = 1e18;
const int maxn = 2e5 + 10;
int n,q;
ll x[maxn];
ll ans[maxn];
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n>>q;
for (int i=1; i<=n; i++) {
cin>>x[i];
}
x[0]=-inf;
x[n+1]=inf;
vector<pair<ll,int>> t;
for (int i=0; i<=n; i++) {
t.push_back({x[i+1]-x[i],i});
}
sort(t.begin(), t.end());
int idx = 0;
ll L = 0;
ll R = 0;
ll at = 0;
while (q--) {
ll w;
cin>>w;
at += w;
if (w>=0) {
R = max(R, at);
while (idx<=n && t[idx].first<=L+R) {
ans[t[idx].second+1] += L;
ans[t[idx].second] += (t[idx].first-L);
idx++;
}
} else {
L = max(L, -at);
while (idx<=n && t[idx].first<=L+R) {
ans[t[idx].second] += R;
ans[t[idx].second+1] += (t[idx].first-R);
idx++;
}
}
}
while (idx<=n) {
ans[t[idx].second] += R;
ans[t[idx].second+1] += L;
idx++;
}
for (int i=1; i<=n; i++) {
cout<<ans[i]<<"\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
2 ms |
492 KB |
Output is correct |
7 |
Correct |
2 ms |
492 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
2 ms |
492 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
11 |
Correct |
2 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
3 ms |
492 KB |
Output is correct |
16 |
Correct |
2 ms |
492 KB |
Output is correct |
17 |
Correct |
2 ms |
492 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
2 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
2 ms |
492 KB |
Output is correct |
7 |
Correct |
2 ms |
492 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
2 ms |
492 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
11 |
Correct |
2 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
3 ms |
492 KB |
Output is correct |
16 |
Correct |
2 ms |
492 KB |
Output is correct |
17 |
Correct |
2 ms |
492 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
2 ms |
492 KB |
Output is correct |
20 |
Correct |
30 ms |
364 KB |
Output is correct |
21 |
Correct |
30 ms |
364 KB |
Output is correct |
22 |
Correct |
31 ms |
492 KB |
Output is correct |
23 |
Correct |
26 ms |
512 KB |
Output is correct |
24 |
Correct |
30 ms |
1260 KB |
Output is correct |
25 |
Correct |
96 ms |
8412 KB |
Output is correct |
26 |
Correct |
96 ms |
8284 KB |
Output is correct |
27 |
Correct |
98 ms |
8284 KB |
Output is correct |
28 |
Correct |
98 ms |
8156 KB |
Output is correct |
29 |
Correct |
95 ms |
8156 KB |
Output is correct |
30 |
Correct |
91 ms |
7516 KB |
Output is correct |
31 |
Correct |
86 ms |
7132 KB |
Output is correct |
32 |
Correct |
71 ms |
7132 KB |
Output is correct |
33 |
Correct |
11 ms |
1260 KB |
Output is correct |
34 |
Correct |
100 ms |
8412 KB |
Output is correct |
35 |
Correct |
111 ms |
8156 KB |
Output is correct |
36 |
Correct |
97 ms |
8304 KB |
Output is correct |
37 |
Correct |
95 ms |
8156 KB |
Output is correct |
38 |
Correct |
94 ms |
8156 KB |
Output is correct |
39 |
Correct |
96 ms |
8224 KB |
Output is correct |
40 |
Correct |
95 ms |
8156 KB |
Output is correct |
41 |
Correct |
33 ms |
364 KB |
Output is correct |
42 |
Correct |
85 ms |
7260 KB |
Output is correct |
43 |
Correct |
106 ms |
8412 KB |
Output is correct |
44 |
Correct |
34 ms |
364 KB |
Output is correct |
45 |
Correct |
91 ms |
8156 KB |
Output is correct |
46 |
Correct |
96 ms |
8464 KB |
Output is correct |
47 |
Correct |
98 ms |
8412 KB |
Output is correct |
48 |
Correct |
96 ms |
8540 KB |
Output is correct |