QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#239174 | #6564. Frequent Flier | Fyind# | TL | 1ms | 3452kb | C++20 | 1.5kb | 2023-11-04 18:59:09 | 2023-11-04 18:59:09 |
Judging History
answer
#include <bits/stdc++.h>
#define mp(x, y) make_pair(x, y)
#define fi first
#define se second
using namespace std;
typedef long long ll;
void solve() {
int n, m, k;
cin >> n >> m >> k;
vector<ll> a(n + m + 1), cnt(n + 1);
for (int i = 1; i <= n; ++i)
cin >> a[i];
ll cur = 0;
ll ans = 0;
priority_queue<pair<int, ll>> q;
for (int i = 1; i <= min(n, m); ++i) {
cnt[i] = min(a[i], k - cur), cur += cnt[i];
ans += cnt[i];
if (a[i] - cnt[i] > 0)
q.push({i, a[i] - cnt[i]});
}
// cout << ans << endl;
for (int i = m + 1; i <= n + m - 1; ++i) {
cur -= cnt[i - m];
q.push({i, a[i]});
while (!q.empty() && cur < k) {
while (q.top().fi <= i - m)
q.pop();
if (q.top().se > k - cur) {
auto [p, v] = q.top();
q.pop();
q.push({p, v - (k - cur)});
ans += (k - cur);
cnt[p] += (k - cur);
cur = k;
}
else
cnt[q.top().fi] += q.top().se, ans += q.top().se, cur += q.top().se, q.pop();
}
// cout << i << ':' << ans << endl;
}
cout << ans << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
#ifdef LLOCAL
freopen("a.in", "r", stdin);
#endif
// int t;
// cin >> t;
// while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3452kb
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...