# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
475895 | 2021-09-24T10:26:50 Z | Jarif_Rahman | Snowball (JOI21_ho_t2) | C++17 | 148 ms | 11600 KB |
#include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; const ll inf = 1e13; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n, q; cin >> n >> q; vector<ll> v(n); for(ll &x: v) cin >> x; vector<ll> w(q); for(ll &x: w) cin >> x; vector<ll> sum(q+1); sum[0] = 0; for(int i = 0; i < q; i++) sum[i+1] = sum[i]+w[i]; vector<pair<ll, ll>> pos, neg; pos.pb({0, 0}); neg.pb({0, 0}); ll a = 0, b = 0; for(int i = 1; i <= q; i++){ if(sum[i] == 0) continue; if(sum[i] > 0 && sum[i] > b){ b = sum[i]; pos.pb({b, -a}); } if(sum[i] < 0 && sum[i] < a){ a = sum[i]; neg.pb({-a, b}); } } vector<ll> ans(n, 0); for(int i = 0; i < n; i++){ if(i == 0){ ans[i]+=neg.back().f; } else{ int a = 0, b = neg.size(); b--; while(a < b){ int md = (a+b+1)/2; if(neg[md].f+neg[md].sc > v[i]-v[i-1]) b = md-1; else a = md; } ll cur = neg[a].f; if(a+1 != neg.size()) cur = max(cur, v[i]-v[i-1]-neg[a+1].sc); ans[i]+=cur; } if(i == n-1){ ans[i]+=pos.back().f; } else{ int a = 0, b = pos.size(); b--; while(a < b){ int md = (a+b+1)/2; if(pos[md].f+pos[md].sc > v[i+1]-v[i]) b = md-1; else a = md; } ll cur = pos[a].f; if(a+1 != pos.size()) cur = max(cur, v[i+1]-v[i]-pos[a+1].sc); ans[i]+=cur; } } for(ll x: ans) cout << x << "\n"; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 2 ms | 460 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 3 ms | 332 KB | Output is correct |
7 | Correct | 2 ms | 332 KB | Output is correct |
8 | Correct | 1 ms | 332 KB | Output is correct |
9 | Correct | 1 ms | 332 KB | Output is correct |
10 | Correct | 2 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 | 332 KB | Output is correct |
17 | Correct | 1 ms | 460 KB | Output is correct |
18 | Correct | 1 ms | 204 KB | Output is correct |
19 | Correct | 1 ms | 332 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 2 ms | 460 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 3 ms | 332 KB | Output is correct |
7 | Correct | 2 ms | 332 KB | Output is correct |
8 | Correct | 1 ms | 332 KB | Output is correct |
9 | Correct | 1 ms | 332 KB | Output is correct |
10 | Correct | 2 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 | 332 KB | Output is correct |
17 | Correct | 1 ms | 460 KB | Output is correct |
18 | Correct | 1 ms | 204 KB | Output is correct |
19 | Correct | 1 ms | 332 KB | Output is correct |
20 | Correct | 36 ms | 6692 KB | Output is correct |
21 | Correct | 31 ms | 6608 KB | Output is correct |
22 | Correct | 35 ms | 6728 KB | Output is correct |
23 | Correct | 33 ms | 6768 KB | Output is correct |
24 | Correct | 46 ms | 6980 KB | Output is correct |
25 | Correct | 148 ms | 11348 KB | Output is correct |
26 | Correct | 137 ms | 11416 KB | Output is correct |
27 | Correct | 140 ms | 10952 KB | Output is correct |
28 | Correct | 141 ms | 10664 KB | Output is correct |
29 | Correct | 130 ms | 9220 KB | Output is correct |
30 | Correct | 86 ms | 7372 KB | Output is correct |
31 | Correct | 61 ms | 6872 KB | Output is correct |
32 | Correct | 59 ms | 6876 KB | Output is correct |
33 | Correct | 12 ms | 1356 KB | Output is correct |
34 | Correct | 101 ms | 8284 KB | Output is correct |
35 | Correct | 111 ms | 8384 KB | Output is correct |
36 | Correct | 141 ms | 11180 KB | Output is correct |
37 | Correct | 140 ms | 10280 KB | Output is correct |
38 | Correct | 140 ms | 10960 KB | Output is correct |
39 | Correct | 136 ms | 10936 KB | Output is correct |
40 | Correct | 88 ms | 10872 KB | Output is correct |
41 | Correct | 35 ms | 7640 KB | Output is correct |
42 | Correct | 61 ms | 6852 KB | Output is correct |
43 | Correct | 124 ms | 11432 KB | Output is correct |
44 | Correct | 36 ms | 6704 KB | Output is correct |
45 | Correct | 75 ms | 10956 KB | Output is correct |
46 | Correct | 102 ms | 11600 KB | Output is correct |
47 | Correct | 90 ms | 9448 KB | Output is correct |
48 | Correct | 92 ms | 11320 KB | Output is correct |