제출 #340415

#제출 시각아이디문제언어결과실행 시간메모리
340415mihai145Solar Storm (NOI20_solarstorm)C++14
36 / 100
558 ms116324 KiB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

/*
ifstream cin("txt.in");
ofstream cout("txt.out");
*/

const int NMAX = 1e6;
const long long INF = 1e15;
const int LGMAX = 20;

int N, S;
long long K, d[NMAX + 5], v[NMAX + 5];

int opt[NMAX + 5], lft[NMAX + 5];
int binaryLift[NMAX + 2][LGMAX + 2];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> N >> S >> K;

    d[0] = -INF;
    d[1] = 0;
    for(int i = 2; i <= N; i++)
    {
        cin >> d[i];
        d[i] += d[i - 1];
    }

    v[0] = 0;
    for(int i = 1; i <= N; i++)
    {
        cin >> v[i];
        v[i] += v[i - 1];
    }

    int j = 0;
    for(int i = 1; i <= N; i++)
    {
        while(j < i && d[i] - d[j] > K)
            j++;

        opt[i] = j;
        lft[i] = j - 1;
        binaryLift[i][0] = lft[opt[i]];
    }

    for(int step = 1; step <= LGMAX; step++)
        for(int i = 1; i <= N; i++)
            binaryLift[i][step] = binaryLift[binaryLift[i][step - 1]][step - 1];

    pair <long long, pair<int, int>> bst = {-1, {0, 0}};

    for(int rg = 1; rg <= N; rg++)
    {

        int s = S, lf = rg;

        for(int step = LGMAX; step >= 0; step--)
            if(s >= (1 << step))
            {
                lf = binaryLift[lf][step];
                s -= (1 << step);
            }

        bst = max(bst, {v[rg] - v[lf], {lf, rg}});
    }

    vector <int> sol;

    int curr = bst.second.second;
    while(curr > bst.second.first)
    {
        sol.push_back(opt[curr]);
        curr = binaryLift[opt[curr]][0];
    }

    reverse(sol.begin(), sol.end());

    cout << (int)sol.size() << '\n';
    for(auto it : sol)
        cout << it << ' ';

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...