Submission #700891

# Submission time Handle Problem Language Result Execution time Memory
700891 2023-02-19T10:56:06 Z bebra Snowball (JOI21_ho_t2) C++17
33 / 100
2500 ms 2344 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define dbg(x) cerr << #x << ": " << x << endl;



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, q;
    cin >> n >> q;
    vector<ll> a(n);
    for (auto& x : a) {
        cin >> x;
    }

    ll max_value = 0;
    ll min_value = 0;

    ll curr_value = 0;
    vector<ll> ans(n);
    vector<ll> space(n - 1);
    for (int i = 0; i < n - 1; ++i) {
        space[i] = a[i + 1] - a[i];
    }
    while (q--) {
        ll w;
        cin >> w;
        curr_value += w;
        if (w > 0) {
            if (curr_value <= max_value) continue;
            
            ll d = curr_value - max_value;
            max_value = max(max_value, curr_value);

            ans[n - 1] += d;
            for (int i = 0; i < n - 1; ++i) {
                ll r = min(d, space[i]);
                space[i] -= r;
                ans[i] += r;
            }
        } else {
            if (curr_value >= min_value) continue;

            ll d = min_value - curr_value;
            min_value = min(min_value, curr_value);

            ans[0] += d;
            for (int i = 1; i < n; ++i) {
                ll r = min(d, space[i - 1]);
                space[i - 1] -= r;
                ans[i] += r;
            }
        }
    }


    for (auto x : ans) {
        cout << x << '\n';
    }

    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 9 ms 408 KB Output is correct
5 Correct 9 ms 340 KB Output is correct
6 Correct 9 ms 336 KB Output is correct
7 Correct 9 ms 368 KB Output is correct
8 Correct 8 ms 328 KB Output is correct
9 Correct 5 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 9 ms 340 KB Output is correct
16 Correct 9 ms 416 KB Output is correct
17 Correct 8 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 9 ms 408 KB Output is correct
5 Correct 9 ms 340 KB Output is correct
6 Correct 9 ms 336 KB Output is correct
7 Correct 9 ms 368 KB Output is correct
8 Correct 8 ms 328 KB Output is correct
9 Correct 5 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 9 ms 340 KB Output is correct
16 Correct 9 ms 416 KB Output is correct
17 Correct 8 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 26 ms 2344 KB Output is correct
21 Correct 28 ms 2220 KB Output is correct
22 Correct 74 ms 1964 KB Output is correct
23 Correct 767 ms 1996 KB Output is correct
24 Execution timed out 2553 ms 1552 KB Time limit exceeded
25 Halted 0 ms 0 KB -