# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
386512 |
2021-04-06T17:16:24 Z |
sahil_k |
Snowball (JOI21_ho_t2) |
C++14 |
|
261 ms |
15708 KB |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
long long pos[n];
for (int i=0; i<n; i++) {
cin >> pos[i];
}
long long wind[q];
for (int i=0; i<q; i++) {
cin >> wind[i];
}
long long cur = 0, f = 0, b = 0;
vector< pair<long long, long long> > vf, vb;
vf.push_back(make_pair(0, 0));
vb.push_back(make_pair(0, 0));
for (int i=0; i<q; i++) {
cur += wind[i];
if (cur > f) {
f = cur;
vf.push_back(make_pair(f+b, b));
}
if (-cur > b) {
b = -cur;
vb.push_back(make_pair(f+b, f));
}
}
vf.push_back(make_pair(1e18, 1e18));
vb.push_back(make_pair(1e18, 1e18));
long long o[n];
for (int i=0; i<n; i++) {
o[i] = 0;
if (i == 0 || pos[i]-pos[i-1] >= f+b) {
o[i] += b;
} else {
pair<long long, long long> val1 = *lower_bound(vb.begin(), vb.end(), make_pair(pos[i]-pos[i-1], -1ll));
pair<long long, long long> val2 = *lower_bound(vf.begin(), vf.end(), make_pair(pos[i]-pos[i-1], -1ll));
if (val1.first < val2.first) {
o[i] += pos[i]-pos[i-1]-val1.second;
} else {
o[i] += val2.second;
}
}
if (i == n-1 || pos[i+1]-pos[i] >= f+b) {
o[i] += f;
} else {
pair<long long, long long> val1 = *lower_bound(vf.begin(), vf.end(), make_pair(pos[i+1]-pos[i], -1ll));
pair<long long, long long> val2 = *lower_bound(vb.begin(), vb.end(), make_pair(pos[i+1]-pos[i], -1ll));
if (val1.first < val2.first) {
o[i] += pos[i+1]-pos[i]-val1.second;
} else {
o[i] += val2.second;
}
}
cout << o[i] << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
492 KB |
Output is correct |
2 |
Correct |
2 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
492 KB |
Output is correct |
4 |
Correct |
3 ms |
492 KB |
Output is correct |
5 |
Correct |
3 ms |
492 KB |
Output is correct |
6 |
Correct |
2 ms |
492 KB |
Output is correct |
7 |
Correct |
3 ms |
492 KB |
Output is correct |
8 |
Correct |
3 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
492 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 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 |
3 ms |
492 KB |
Output is correct |
17 |
Correct |
2 ms |
492 KB |
Output is correct |
18 |
Correct |
2 ms |
364 KB |
Output is correct |
19 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
492 KB |
Output is correct |
2 |
Correct |
2 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
492 KB |
Output is correct |
4 |
Correct |
3 ms |
492 KB |
Output is correct |
5 |
Correct |
3 ms |
492 KB |
Output is correct |
6 |
Correct |
2 ms |
492 KB |
Output is correct |
7 |
Correct |
3 ms |
492 KB |
Output is correct |
8 |
Correct |
3 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
492 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 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 |
3 ms |
492 KB |
Output is correct |
17 |
Correct |
2 ms |
492 KB |
Output is correct |
18 |
Correct |
2 ms |
364 KB |
Output is correct |
19 |
Correct |
2 ms |
364 KB |
Output is correct |
20 |
Correct |
35 ms |
7356 KB |
Output is correct |
21 |
Correct |
39 ms |
7132 KB |
Output is correct |
22 |
Correct |
35 ms |
7000 KB |
Output is correct |
23 |
Correct |
32 ms |
6864 KB |
Output is correct |
24 |
Correct |
46 ms |
7228 KB |
Output is correct |
25 |
Correct |
195 ms |
13564 KB |
Output is correct |
26 |
Correct |
212 ms |
13648 KB |
Output is correct |
27 |
Correct |
198 ms |
13016 KB |
Output is correct |
28 |
Correct |
186 ms |
13008 KB |
Output is correct |
29 |
Correct |
173 ms |
11076 KB |
Output is correct |
30 |
Correct |
115 ms |
9068 KB |
Output is correct |
31 |
Correct |
77 ms |
8428 KB |
Output is correct |
32 |
Correct |
81 ms |
8556 KB |
Output is correct |
33 |
Correct |
17 ms |
1772 KB |
Output is correct |
34 |
Correct |
145 ms |
10860 KB |
Output is correct |
35 |
Correct |
157 ms |
10600 KB |
Output is correct |
36 |
Correct |
261 ms |
13400 KB |
Output is correct |
37 |
Correct |
187 ms |
12496 KB |
Output is correct |
38 |
Correct |
189 ms |
12960 KB |
Output is correct |
39 |
Correct |
216 ms |
13144 KB |
Output is correct |
40 |
Correct |
111 ms |
13080 KB |
Output is correct |
41 |
Correct |
37 ms |
8932 KB |
Output is correct |
42 |
Correct |
65 ms |
8556 KB |
Output is correct |
43 |
Correct |
112 ms |
15184 KB |
Output is correct |
44 |
Correct |
37 ms |
7892 KB |
Output is correct |
45 |
Correct |
77 ms |
13264 KB |
Output is correct |
46 |
Correct |
115 ms |
15312 KB |
Output is correct |
47 |
Correct |
104 ms |
13412 KB |
Output is correct |
48 |
Correct |
106 ms |
15708 KB |
Output is correct |