답안 #897235

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
897235 2024-01-02T19:10:38 Z arbuzick Snowball (JOI21_ho_t2) C++17
100 / 100
89 ms 17116 KB
#include <bits/stdc++.h>

using namespace std;

void solve() {
    int n, q;
    cin >> n >> q;
    vector<long long> x(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i];
    }
    vector<long long> w(q), pr(q + 1), pr_mn(q + 1), pr_mx(q + 1);
    for (int i = 0; i < q; ++i) {
        cin >> w[i];
        pr[i + 1] = pr[i] + w[i];
        pr_mn[i + 1] = min(pr_mn[i], pr[i + 1]);
        pr_mx[i + 1] = max(pr_mx[i], pr[i + 1]);
    }
    vector<long long> ans(n);
    for (int i = 0; i < n - 1; ++i) {
        int l = 0, r = q + 1;
        while (l < r - 1) {
            int m = (l + r) / 2;
            if (pr_mx[m] - pr_mn[m] >= x[i + 1] - x[i]) {
                r = m;
            } else {
                l = m;
            }
        }
        if (r == q + 1) {
            ans[i] += pr_mx[q];
            ans[i + 1] -= pr_mn[q];
        } else if (pr[r] > pr[l]) {
            ans[i + 1] -= pr_mn[r];
            ans[i] += x[i + 1] - x[i] + pr_mn[r];
        } else {
            ans[i] += pr_mx[r];
            ans[i + 1] += x[i + 1] - x[i] - pr_mx[r];
        }
    }
    ans[0] -= pr_mn[q];
    ans[n - 1] += pr_mx[q];
    for (int i = 0; i < n; ++i) {
        cout << ans[i] << '\n';
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 21 ms 8792 KB Output is correct
21 Correct 21 ms 8540 KB Output is correct
22 Correct 21 ms 8504 KB Output is correct
23 Correct 19 ms 8284 KB Output is correct
24 Correct 30 ms 8616 KB Output is correct
25 Correct 78 ms 15184 KB Output is correct
26 Correct 76 ms 14932 KB Output is correct
27 Correct 78 ms 14656 KB Output is correct
28 Correct 78 ms 14928 KB Output is correct
29 Correct 79 ms 14256 KB Output is correct
30 Correct 79 ms 13648 KB Output is correct
31 Correct 49 ms 13140 KB Output is correct
32 Correct 50 ms 13280 KB Output is correct
33 Correct 8 ms 1884 KB Output is correct
34 Correct 81 ms 15472 KB Output is correct
35 Correct 77 ms 14928 KB Output is correct
36 Correct 89 ms 14940 KB Output is correct
37 Correct 80 ms 14932 KB Output is correct
38 Correct 78 ms 14672 KB Output is correct
39 Correct 77 ms 14928 KB Output is correct
40 Correct 60 ms 14932 KB Output is correct
41 Correct 21 ms 9308 KB Output is correct
42 Correct 44 ms 13136 KB Output is correct
43 Correct 56 ms 16484 KB Output is correct
44 Correct 21 ms 9308 KB Output is correct
45 Correct 50 ms 14688 KB Output is correct
46 Correct 59 ms 16724 KB Output is correct
47 Correct 59 ms 16976 KB Output is correct
48 Correct 58 ms 17116 KB Output is correct