# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
224272 | bortoz | Solar Storm (NOI20_solarstorm) | C++17 | 409 ms | 130652 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define fi first
#define se second
constexpr int MAXN = 1 << 20, LOGN = 21;
int J[LOGN][MAXN];
ll D[MAXN];
ll C[MAXN];
int lx[MAXN], rx[MAXN];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N, S;
ll K;
cin >> N >> S >> K;
for (int i = 2; i <= N; i++) {
cin >> D[i];
D[i] += D[i - 1];
}
for (int i = 1; i <= N; i++) {
cin >> C[i];
C[i] += C[i - 1];
}
rx[0] = 1;
for (int i = 1, l = 1, r = 1, x = 0; i <= N; i++) {
while (r <= N && D[r] <= D[i] + K) r++;
while (D[l] + K < D[i]) l++;
while (rx[x] < l) x++;
lx[i] = l;
rx[i] = r;
J[0][i] = x;
}
for (int k = 1; k < LOGN; k++) {
for (int i = 1; i <= N; i++) {
J[k][i] = J[k - 1][J[k - 1][i]];
}
}
ll res = 0;
int pos = 0;
for (int i = 1; i <= N; i++) {
int x = i;
for (int k = 0; k < LOGN; k++) {
if ((S - 1) & 1 << k) x = J[k][x];
}
ll T = C[rx[i] - 1] - C[lx[x] - 1];
if (T > res) {
res = T;
pos = i;
}
}
vector<int> sol;
for (int i = 0; i < S && pos > 0; i++) {
sol.push_back(pos);
pos = J[0][pos];
}
reverse(sol.begin(), sol.end());
cout << sol.size() << '\n';
for (int i = 0; i < sol.size(); i++) {
cout << sol[i] << " \n"[i + 1 == sol.size()];
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |