QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#120250 | #6564. Frequent Flier | hos_lyric | AC ✓ | 17ms | 10348kb | C++14 | 2.2kb | 2023-07-06 15:45:35 | 2023-07-06 15:45:38 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
int N, M;
Int K;
vector<Int> F;
int main() {
for (; ~scanf("%d%d%lld", &N, &M, &K); ) {
F.resize(N);
for (int i = 0; i < N; ++i) {
scanf("%lld", &F[i]);
}
const int L = N - 1 + M;
vector<Int> pay(L, 0);
Int now = 0;
int len = 0;
vector<pair<int, Int>> stack(N);
for (int i = 0; i < L; ++i) {
// condition for (i - M, i]
if (i - M >= 0) {
now -= pay[i - M];
}
if (i < N) {
stack[len++] = make_pair(i, F[i]);
}
for (; now < K && len > 0; --len) {
const int j = stack[len - 1].first;
Int &f = stack[len - 1].second;
if (i - M < j) {
const Int t = min(f, K - now);
pay[j] += t;
now += t;
f -= t;
if (f > 0) {
break;
}
}
}
}
// cerr<<"pay = "<<pay<<endl;
Int ans = 0;
for (int i = 0; i < L; ++i) {
ans += pay[i];
}
printf("%lld\n", ans);
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3632kb
input:
8 3 2 3 1 4 1 5 9 2 6
output:
8
result:
ok single line: '8'
Test #2:
score: 0
Accepted
time: 12ms
memory: 9348kb
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:
82994275905
result:
ok single line: '82994275905'
Test #3:
score: 0
Accepted
time: 1ms
memory: 4572kb
input:
1 200000 999959273 1255319
output:
1255319
result:
ok single line: '1255319'
Test #4:
score: 0
Accepted
time: 16ms
memory: 10348kb
input:
200000 118880 996878327 993340390 999483057 808153702 337349872 863222189 7495963 995920883 12950768 958082368 993215196 967152406 1388062 949959944 836952150 964071667 5291 139115263 958470154 51295691 175385 925242139 995685554 10895812 12563 55482 479983443 42805 996241239 6228013 302633329 10331...
output:
2990634981
result:
ok single line: '2990634981'
Test #5:
score: 0
Accepted
time: 17ms
memory: 9484kb
input:
200000 15 44049967 999927791 29351 999894087 687373343 518282902 19725626 452930 6701 999697321 27032796 5498 259987 999999980 485673990 805879 315651507 166801295 189865616 999910671 6203805 978801777 41916529 942904087 997589912 17146790 922137016 444882952 999884603 999926345 938979650 18597283 9...
output:
598769574112
result:
ok single line: '598769574112'