QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#524601 | #6564. Frequent Flier | amirreza# | RE | 0ms | 3568kb | C++23 | 1.3kb | 2024-08-19 20:47:10 | 2024-08-19 20:47:11 |
Judging History
answer
#include <bits/stdc++.h>
#define FOR(i, x, n) for(int i = x; i < n; i++)
#define F0R(i, n) FOR(i, 0, n)
#define ROF(i, x, n) for(int i = n - 1; i >= x; i--)
#define R0F(i, n) ROF(i, 0, n)
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long LL;
const int N = 2e5 + 7;
LL n, m, k;
LL ns[N], bought[N];
stack<int> keep;
int main() {
cin >> n >> m >> k;
LL sumbought = 0;
F0R(i, m - 1) {
keep.push(i);
}
LL ans = 0;
FOR(i, m - 1, n + m - 1 + (m - 1)) {
if (i < n + m - 1) cin >> ns[i];
keep.push(i);
if (i >= m) sumbought -= bought[i - m];
while(sumbought < k) {
if (keep.empty() || keep.top() < i - m + 1) break;
if (sumbought + ns[ keep.top() ] > k) {
bought[keep.top()] += k - sumbought;
ns[ keep.top() ] -= (k - sumbought);
ans += k - sumbought;
sumbought = k;
}
else {
sumbought += ns[ keep.top() ];
bought[ keep.top() ] += ns[ keep.top() ];
ans += ns[keep.top()];
ns[ keep.top() ] = 0;
keep.pop();
}
}
}
cout << ans << endl;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3568kb
input:
8 3 2 3 1 4 1 5 9 2 6
output:
8
result:
ok single line: '8'
Test #2:
score: -100
Runtime Error
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...