#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll BIG = 1234567891234567890;
vector<ll> roll_snowballs(vector<ll> snowballs, vector<ll> wind) {
int n = snowballs.size();
int q = wind.size();
ll le = 0, ri = 0; // Pushes to the right/left
ll curr = 0;
vector<pair<ll, ll>> gaps(n+1);
vector<ll> ans(n);
gaps[0] = {BIG, -1};
gaps[n] = {BIG, n-1};
for(int i = 1; i < n; i++) {
gaps[i] = {snowballs[i] - snowballs[i-1], i-1};
}
sort(gaps.begin(), gaps.end());
int j = 0;
for(int i = 0; i < q; i++) {
curr += wind[i];
if(curr > 0) le = max(le, curr);
if(curr < 0) ri = max(ri, -curr);
while(le + ri >= gaps[j].first) {
ll l = le, r = ri, siz = gaps[j].first;
if(curr > 0) l = siz - r;
if(curr < 0) r = siz - l;
ans[gaps[j].second] += l;
ans[gaps[j].second+1] += r;
j++;
}
}
for(; j < n-1; j++) {
ans[gaps[j].second] += le;
ans[gaps[j].second+1] += ri;
}
ans[0] += ri;
ans[n-1] += le;
return ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
vector<ll> snowballs(n), wind(q);
for(int i = 0; i < n; i++) cin >> snowballs[i];
for(int i = 0; i < q; i++) cin >> wind[i];
vector<ll> ans = roll_snowballs(snowballs, wind);
for(ll a : ans) cout << a << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 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 |
452 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 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 |
452 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
26 ms |
5568 KB |
Output is correct |
21 |
Correct |
27 ms |
5312 KB |
Output is correct |
22 |
Correct |
24 ms |
5152 KB |
Output is correct |
23 |
Correct |
22 ms |
5060 KB |
Output is correct |
24 |
Correct |
25 ms |
5740 KB |
Output is correct |
25 |
Correct |
78 ms |
14904 KB |
Output is correct |
26 |
Correct |
79 ms |
14916 KB |
Output is correct |
27 |
Correct |
77 ms |
14680 KB |
Output is correct |
28 |
Correct |
77 ms |
14956 KB |
Output is correct |
29 |
Correct |
79 ms |
14692 KB |
Output is correct |
30 |
Correct |
73 ms |
14312 KB |
Output is correct |
31 |
Correct |
69 ms |
14188 KB |
Output is correct |
32 |
Correct |
61 ms |
14304 KB |
Output is correct |
33 |
Correct |
8 ms |
1732 KB |
Output is correct |
34 |
Correct |
82 ms |
15332 KB |
Output is correct |
35 |
Correct |
76 ms |
14940 KB |
Output is correct |
36 |
Correct |
79 ms |
14952 KB |
Output is correct |
37 |
Correct |
79 ms |
14940 KB |
Output is correct |
38 |
Correct |
77 ms |
14688 KB |
Output is correct |
39 |
Correct |
77 ms |
14940 KB |
Output is correct |
40 |
Correct |
81 ms |
14936 KB |
Output is correct |
41 |
Correct |
28 ms |
6080 KB |
Output is correct |
42 |
Correct |
68 ms |
14312 KB |
Output is correct |
43 |
Correct |
90 ms |
16580 KB |
Output is correct |
44 |
Correct |
32 ms |
5936 KB |
Output is correct |
45 |
Correct |
75 ms |
14812 KB |
Output is correct |
46 |
Correct |
81 ms |
16608 KB |
Output is correct |
47 |
Correct |
79 ms |
16744 KB |
Output is correct |
48 |
Correct |
80 ms |
16708 KB |
Output is correct |