Submission #937065

#TimeUsernameProblemLanguageResultExecution timeMemory
937065kitlixSnowball (JOI21_ho_t2)C++17
100 / 100
132 ms15444 KiB
#include <bits/stdc++.h>
#define int long long

using namespace std;

signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, q;
    cin >> n >> q;
    vector<int> x(n);
    for (auto& el : x)
        cin >> el;
    vector<int> w(q), wsum(q), curlmax(q), currmax(q);
    int cur = 0, wleftmax = 0, wrightmax = 0;
    for (int i = 0; i < q; ++i) {
        int wi;
        cin >> wi;
        w[i] = wi;
        cur += wi;
        if (cur < 0 && wleftmax < abs(cur))
            wleftmax = abs(cur);
        if (cur > 0 && wrightmax < cur)
            wrightmax = cur;
        curlmax[i] = wleftmax;
        currmax[i] = wrightmax;
        wsum[i] = wleftmax + wrightmax;
    }
    for (int i = 0; i < n; ++i) {
        int ans = 0;
        if (i == 0) {
            ans += wleftmax;
        } else if (x[i] - x[i - 1] >= wsum.back()) {
            ans += wleftmax;
        } else {
            int day = lower_bound(wsum.begin(), wsum.end(), x[i] - x[i - 1]) - wsum.begin();
            if (w[day] < 0)
                ans += (x[i] - x[i - 1]) - currmax[day];
            else
                ans += curlmax[day];
        }
        if (i == n - 1) {
            ans += wrightmax;
        } else if (x[i + 1] - x[i] >= wsum.back()) {
            ans += wrightmax;
        } else {
            int day = lower_bound(wsum.begin(), wsum.end(), x[i + 1] - x[i]) - wsum.begin();
            if (w[day] < 0)
                ans += currmax[day];
            else
                ans += (x[i + 1] - x[i]) - curlmax[day];
        }
        cout << ans << '\n';
    }
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...