# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
937065 |
2024-03-03T10:31:14 Z |
kitlix |
Snowball (JOI21_ho_t2) |
C++17 |
|
132 ms |
15444 KB |
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n, q;
cin >> n >> q;
vector<int> x(n);
for (auto& el : x)
cin >> el;
vector<int> w(q), wsum(q), curlmax(q), currmax(q);
int cur = 0, wleftmax = 0, wrightmax = 0;
for (int i = 0; i < q; ++i) {
int wi;
cin >> wi;
w[i] = wi;
cur += wi;
if (cur < 0 && wleftmax < abs(cur))
wleftmax = abs(cur);
if (cur > 0 && wrightmax < cur)
wrightmax = cur;
curlmax[i] = wleftmax;
currmax[i] = wrightmax;
wsum[i] = wleftmax + wrightmax;
}
for (int i = 0; i < n; ++i) {
int ans = 0;
if (i == 0) {
ans += wleftmax;
} else if (x[i] - x[i - 1] >= wsum.back()) {
ans += wleftmax;
} else {
int day = lower_bound(wsum.begin(), wsum.end(), x[i] - x[i - 1]) - wsum.begin();
if (w[day] < 0)
ans += (x[i] - x[i - 1]) - currmax[day];
else
ans += curlmax[day];
}
if (i == n - 1) {
ans += wrightmax;
} else if (x[i + 1] - x[i] >= wsum.back()) {
ans += wrightmax;
} else {
int day = lower_bound(wsum.begin(), wsum.end(), x[i + 1] - x[i]) - wsum.begin();
if (w[day] < 0)
ans += currmax[day];
else
ans += (x[i + 1] - x[i]) - curlmax[day];
}
cout << ans << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
540 KB |
Output is correct |
4 |
Correct |
1 ms |
516 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
452 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
540 KB |
Output is correct |
4 |
Correct |
1 ms |
516 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
2 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
452 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
20 ms |
8628 KB |
Output is correct |
21 |
Correct |
19 ms |
8532 KB |
Output is correct |
22 |
Correct |
18 ms |
8280 KB |
Output is correct |
23 |
Correct |
20 ms |
8248 KB |
Output is correct |
24 |
Correct |
24 ms |
8552 KB |
Output is correct |
25 |
Correct |
105 ms |
13516 KB |
Output is correct |
26 |
Correct |
121 ms |
13456 KB |
Output is correct |
27 |
Correct |
95 ms |
13136 KB |
Output is correct |
28 |
Correct |
96 ms |
13136 KB |
Output is correct |
29 |
Correct |
115 ms |
12668 KB |
Output is correct |
30 |
Correct |
106 ms |
12228 KB |
Output is correct |
31 |
Correct |
50 ms |
11604 KB |
Output is correct |
32 |
Correct |
55 ms |
11616 KB |
Output is correct |
33 |
Correct |
12 ms |
2004 KB |
Output is correct |
34 |
Correct |
132 ms |
13904 KB |
Output is correct |
35 |
Correct |
95 ms |
13144 KB |
Output is correct |
36 |
Correct |
94 ms |
13392 KB |
Output is correct |
37 |
Correct |
114 ms |
13132 KB |
Output is correct |
38 |
Correct |
100 ms |
13012 KB |
Output is correct |
39 |
Correct |
89 ms |
13388 KB |
Output is correct |
40 |
Correct |
58 ms |
13276 KB |
Output is correct |
41 |
Correct |
21 ms |
9300 KB |
Output is correct |
42 |
Correct |
57 ms |
11592 KB |
Output is correct |
43 |
Correct |
56 ms |
14928 KB |
Output is correct |
44 |
Correct |
20 ms |
9308 KB |
Output is correct |
45 |
Correct |
46 ms |
13128 KB |
Output is correct |
46 |
Correct |
59 ms |
15192 KB |
Output is correct |
47 |
Correct |
57 ms |
15440 KB |
Output is correct |
48 |
Correct |
58 ms |
15444 KB |
Output is correct |