QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#239585 | #6564. Frequent Flier | ElyesChaabouni# | RE | 0ms | 0kb | C++14 | 1.5kb | 2023-11-04 21:30:32 | 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