QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#112406 | #6564. Frequent Flier | ckiseki# | RE | 44ms | 29896kb | C++20 | 2.4kb | 2023-06-11 16:40:14 | 2023-06-11 16:40:15 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#ifdef CKISEKI
#define safe cerr << __PRETTY_FUNCTION__ << " line " << __LINE__ << " safe\n"
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
template <typename ...T>
void debug_(const char *s, T ...a) {
cerr << "\e[1;32m(" << s << ") = (";
int cnt = sizeof...(T);
(..., (cerr << a << (--cnt ? ", " : ")\e[0m\n")));
}
template <typename I>
void orange_(const char *s, I L, I R) {
cerr << "\e[1;32m[ " << s << " ] = [ ";
for (int f = 0; L != R; ++L)
cerr << (f++ ? ", " : "") << *L;
cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) ((void)0)
#define orange(...) ((void)0)
#endif
template <typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, m, k;
cin >> n >> m >> k;
vector<int64_t> a(n), p(n + 1);
vector<int> tag(n + 1);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
p[i + 1] = p[i] + a[i];
}
vector<vector<pair<int,int64_t>>> g(n + 1);
const auto check = [&](int l, int r) {
if (p[r] - p[l] >= k) {
g[l].emplace_back(r, p[r] - p[l] - k);
debug(l, r, p[r]-p[l]-k);
} else {
tag[l] += 1;
tag[r] -= 1;
}
};
for (int i = 0; i < m; i++) {
check(0, i + 1);
check(n - i - 1, n);
}
for (int i = 0; i + m <= n; i++) {
check(i, i + m);
}
for (int i = 1; i <= n; i++) {
tag[i] += tag[i - 1];
}
orange(tag.begin(), tag.end());
for (int i = 0; i < n; i++) {
if (tag[i] == 0) {
g[i].emplace_back(i + 1, a[i]);
g[i + 1].emplace_back(i, 0);
} else {
g[i].emplace_back(i + 1, 0);
g[i + 1].emplace_back(i, 0);
}
}
vector<int64_t> dis(n + 1, 1e18);
vector<int> vis(n + 1);
min_heap<pair<int64_t,int>> pq;
pq.emplace(0, 0);
dis[0] = 0;
while (!pq.empty()) {
auto [_, i] = pq.top(); pq.pop();
if (vis[i]) continue;
vis[i] = true;
for (auto [j, w]: g[i]) {
if (dis[j] > dis[i] + w)
dis[j] = dis[i] + w, pq.emplace(dis[j], j);
}
}
debug(dis[n], p[n]);
cout << p[n] - dis[n] << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3340kb
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: 44ms
memory: 29896kb
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: -100
Runtime Error
input:
1 200000 999959273 1255319