QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#359612#6564. Frequent FlierLaStataleBlue#TL 0ms3620kbC++231.9kb2024-03-20 19:27:072024-03-20 19:27:07

Judging History

你现在查看的是最新测评结果

  • [2024-03-20 19:27:07]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3620kb
  • [2024-03-20 19:27:07]
  • 提交

answer

#pragma ide diagnostic ignored "misc-no-recursion"

#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;

#define TESTCASE 0

static constexpr int MAXN = 2e5 + 10;

struct DSU {
    vector<int> p, s, f;

    void init(int n) {
        p.assign(n, -1);
        s.assign(n, 1);
        f.resize(n);
        iota(f.begin(), f.end(), 0);
    }

    int find(int x) {
        if (p[x] == -1)
            return x;
        return p[x] = find(p[x]);
    }

    void join(int a, int b) {
        a = find(a);
        b = find(b);
        if (a == b)
            return;
        if (s[a] > s[b])
            swap(a, b);
        p[a] = b;
        s[b] += s[a];
        f[b] = min(f[a], f[b]);
    }
};

int a[2 * MAXN];
int b[2 * MAXN];
DSU dsu;

static void solve([[maybe_unused]] int tc) {
    int N, M, K;
    cin >> N >> M >> K;
    for (int i = 1; i <= N; ++i)
        cin >> b[i];

    dsu.init(1 + N + M);
    ll ans = 0;
    ll asum = 0, bsum = 0;
    for (int i = 1; i <= N + M; i++) {
        bsum += b[i] - (i - M >= 0 ? b[i - M] : 0);
        asum += -(i - M >= 0 ? a[i - M] : 0);
        int pos = i;
        while (asum < bsum && asum < K) {
            pos = dsu.find(pos);
            if (pos <= i - M)
                break;
            int toadd = min(min(bsum, ll(K)) - asum, (ll) b[pos] - a[pos]);
            a[pos] += toadd;
            asum += toadd;
            ans += toadd;
            if (a[pos] == b[pos])
                dsu.join(pos, pos - 1);
        }
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);

    if (const char *f = getenv("REDIRECT_STDOUT"); f) {
        freopen(f, "w", stdout);
    }

    int T = 1;
#if TESTCASE
    cin >> T;
#endif

    for (int t = 1; t <= T; t++) {
        solve(t);
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3620kb

input:

8 3 2
3
1
4
1
5
9
2
6

output:

8

result:

ok single line: '8'

Test #2:

score: -100
Time Limit Exceeded

input:

200000 2467 999931035
182548858
69876218
33328350
919486767
739850600
948199964
392292320
39077742
366752074
917496841
246661698
37219034
56677740
188278971
965701828
28059790
13200243
825730775
542597589
320715170
939054378
470563899
914247467
990100491
290827128
903662394
611104879
18631185
412134...

output:


result: