Submission #1366330

#TimeUsernameProblemLanguageResultExecution timeMemory
1366330kawhietSnowball (JOI21_ho_t2)C++20
100 / 100
45 ms8264 KiB
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...) 47
#endif

#define int long long

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, q;
    cin >> n >> q;
    vector<int> x(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    vector<array<int, 2>> d;
    for (int i = 1; i < n; i++) {
        d.push_back({x[i] - x[i - 1], i - 1});
    }
    sort(d.begin(), d.end());
    vector<int> ans(n);
    vector<bool> is(n);
    int mn = 0, mx = 0, s = 0, pos = 0;
    while (q--) {
        int w;
        cin >> w;
        s += w;
        mx = max(mx, s);
        mn = min(mn, s);
        int k = mx - mn;
        while (pos < n - 1 && d[pos][0] <= k) {
            int j = d[pos][1];
            if (w > 0) {
                ans[j + 1] -= mn;
                ans[j] += d[pos][0] + mn;
            } else {
                ans[j] += mx;
                ans[j + 1] += d[pos][0] - mx;
            }
            is[j] = true;
            pos++;
        }
    }
    ans[0] -= mn;
    ans[n - 1] += mx;
    for (int i = 0; i < n - 1; i++) {
        if (!is[i]) {
            ans[i] += mx;
            ans[i + 1] -= mn;
        }
    }
    for (int i = 0; i < n; i++) {
        cout << ans[i] << '\n';
    }
    return 0;
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...