| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 1277163 | ducdev | Solar Storm (NOI20_solarstorm) | C++17 | 2097 ms | 27824 KiB | 
// Author: 4uckd3v - Nguyen Cao Duc
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N = 1e6;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
int n, s;
int d[MAX_N + 5], v[MAX_N + 5];
ll k;
ll pref[MAX_N + 5];
ll getSum(int l, int r) {
    if (l > r) return 0;
    return pref[r] - (l == 0 ? 0 : pref[l - 1]);
};
namespace SUBTASK_12356 {
    const int LIM = 1e8;
    const int N = MAX_N;
    int L[N + 5], R[N + 5], nextPos[N + 5];
    void Solve() {
        ll dist = 0;
        for (int i = 1; i <= n; i++) {
            L[i] = max(1, L[i - 1]);
            while (L[i] < i && dist > k) {
                dist -= d[L[i]];
                L[i]++;
            };
            dist += d[i];
        };
        dist = 0;
        R[n] = n;
        for (int i = n - 1; i >= 1; i--) {
            dist += d[i];
            R[i] = R[i + 1];
            while (R[i] > i && dist > k) {
                dist -= d[R[i] - 1];
                R[i]--;
            };
        };
        for (int i = 1; i <= n; i++) {
            nextPos[i] = max(i, nextPos[i - 1]);
            while (nextPos[i] < n && L[nextPos[i] + 1] <= R[i] + 1) nextPos[i]++;
            if (nextPos[i] <= i) nextPos[i] = -1;
        };
        ll res = 0;
        int traceIdx = 0, traceCnt = 0;
        for (int i = 1; i <= n; i++) {
            ll sum = 0;
            int cnt = 0, curPos = i;
            while (true) {
                cnt++;
                if (nextPos[curPos] == -1 || cnt == s) {
                    sum += getSum(L[curPos], R[curPos]);
                    break;
                };
                sum += getSum(L[curPos], L[nextPos[curPos]] - 1);
                curPos = nextPos[curPos];
            };
            if (res < sum) {
                res = sum;
                traceIdx = i;
                traceCnt = cnt;
            };
        };
        cout << traceCnt << '\n';
        while (true) {
            traceCnt--;
            cout << traceIdx << ' ';
            if (nextPos[traceIdx] == -1 || traceCnt == 0) break;
            traceIdx = nextPos[traceIdx];
        };
    };
};  // namespace SUBTASK_12356
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if (fopen("MAIN.INP", "r")) {
        freopen("MAIN.INP", "r", stdin);
        freopen("MAIN.OUT", "w", stdout);
    };
    cin >> n >> s >> k;
    for (int i = 1; i < n; i++) {
        cin >> d[i];
    };
    for (int i = 1; i <= n; i++) {
        cin >> v[i];
        pref[i] = pref[i - 1] + v[i];
    };
    SUBTASK_12356::Solve();
};
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... | ||||
