QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#239585#6564. Frequent FlierElyesChaabouni#RE 0ms0kbC++141.5kb2023-11-04 21:30:322023-11-04 21:30:32

Judging History

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

  • [2023-11-04 21:30:32]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-11-04 21:30:32]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

const int MAXN = 200 * 1000 + 123;

ll a[MAXN];
bitset<MAXN> mark;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    ll n, m, k;
    cin >> n >> m >> k;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    deque<pll> d;
    ll cur = 0, ans = 0;
    for (int i = 0; i < n + m; i++) {
        d.push_back({i, a[i]});
        while (!d.empty() && d.front().first <= i - m) {
            //ans += a[d.front().first] - d.front().second;
            //cerr << d.front().first << ' ' << a[d.front().first] - d.front().second << endl;
            cur -= a[d.front().first] - d.front().second;
            d.pop_front();
        }
        if (mark[i - m]) {
            cur -= a[i - m];
        }
        //cout << "curd8 " << i << ' ' << cur << endl;
        while (cur < k && !d.empty()) {
            if (d.back().second + cur <= k) {
                cur += d.back().second;
                ans += d.back().second;//a[d.back().first];
                mark[d.back().first] = true;
                //cerr << "yo " << d.back().first - m << ' ' << a[d.back().first] << endl;
                d.pop_back();
            } else {
                d.back().second -= (k - cur);
                ans += (k - cur);
                cur = k;
            }
        }
        //cout << "curd " << i << ' ' << cur << endl;
    }
    cout << ans;
    return 0;
}
/*
8 3 2
3
1
4
1
5
9
2
6
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

8 3 2
3
1
4
1
5
9
2
6

output:


result: