제출 #1344797

#제출 시각아이디문제언어결과실행 시간메모리
1344797iamhereforfunSnowball (JOI21_ho_t2)C++20
100 / 100
54 ms11388 KiB
// Starcraft 2 enjoyer //

#include <bits/stdc++.h>

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

using namespace std;

#define LSOne(X) ((X) & -(X))

const int N = 1e6 + 5;
const int M = 1e6 + 5;
const int K = 20;
const int LG = 21;
const long long INF = 1e18 + 5;
const int C = 26;
const int B = 1000;
const int MOD = 998244353;

long long n, q, p[N], w[N], cur, mx[N], mn[N], sum[N], ans[N];

inline void solve()
{
    cin >> n >> q;
    for (int x = 0; x < n; x++)
    {
        cin >> p[x];
    }
    mx[0] = 0;
    mn[0] = 0;
    for (int x = 1; x <= q; x++)
    {
        cin >> w[x];
        cur += w[x];
        mx[x] = max(mx[x - 1], cur);
        mn[x] = min(mn[x - 1], cur);
        sum[x] = mx[x] - mn[x];
    }
    for (int x = 0; x < n - 1; x++)
    {
        int i = lower_bound(sum + 1, sum + q + 1, p[x + 1] - p[x]) - sum;
        // cout << sum[i] << " ";
        if (i > q)
        {
            ans[x] += mx[q];
            ans[x + 1] -= mn[q];
        }
        else
        {
            if (mx[i] > mx[i - 1])
            {
                ans[x] += (p[x + 1] - p[x]) + mn[i - 1];
                ans[x + 1] -= mn[i - 1];
            }
            else
            {
                ans[x] += mx[i - 1];
                ans[x + 1] += (p[x + 1] - p[x]) - mx[i - 1];
            }
        }
    }
    // cout << "\n";
    // cout << ans[0] << "\n";
    ans[0] -= mn[q];
    ans[n - 1] += mx[q];
    for (int x = 0; x < n; x++)
    {
        cout << ans[x] << "\n";
    }
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    for (int x = 1; x <= t; x++)
    {
        solve();
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...