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 <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define REP(i,a,b) for(ll i=a; i<b; i++)
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define ff first
#define ss second
#define INF 100000000000000000LL
ll insig;
#define In(vecBRO, LENBRO) REP(IBRO,0,LENBRO) {cin>>insig; vecBRO.pb(insig);}
void Out(vector<ll> x) {REP(i,0,x.size()) {cout<<x[i]<<" ";} cout<<endl;}
class SucPath
{
    public:
    ll N;
    vector<int> fo;
    vector<vector<int> > f2; //sparse table of steps powers of 2
    ll ms; //max_steps
    
    SucPath(vector<int> x, ll max_steps) 
    {
        N=x.size(); fo=x; ms=max_steps;
        vector<int> xx;
        REP(i,0,(ll) (floor(log2(ms)))+1LL) {xx.pb(0);}
        REP(i,0,N) {f2.pb(xx);}
        Conf2(0);
    }
    
    void Conf2(ll e) //O(NlogN)
    {
        if((1LL<<e)>ms) {return;}
        if(e==0) {REP(i,0,N) {f2[i][e]=fo[i];} Conf2(e+1);}
        else 
        {
            REP(i,0,N) 
            {
                f2[i][e]=f2[f2[i][e-1]][e-1];
            }
        }
        Conf2(e+1);
    }
    
    ll f(ll x,ll s) //O(logN)
    {
        ll ind=0; 
        while(s>0) 
        {
            if(s%2!=0) {x=f2[x][ind];}
            s/=2; ind++;
        }
        return x;
    }
};
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll N,S,K; cin>>N>>S>>K;
    vector<ll> p,d,v; In(d,N-1); In(v,N);
    p.pb(0LL); ll curpos=0LL;
    REP(i,0,N-1) {curpos+=d[i]; p.pb(curpos);}
    vector<int> nxt; vector<ll> cen;
    REP(i,0,N)
    {
        ll val = (ll) (upper_bound(p.begin(),p.end(),p[i]+K)-p.begin()); val--;
        cen.pb(val);
        val=(ll) (upper_bound(p.begin(),p.end(),p[val]+K)-p.begin()); val--;
        nxt.pb(val+1);
    }
    nxt.pb(N);
    SucPath P(nxt,S);
    vector<ll> ps; ll cursum=0LL; ps.pb(cursum); REP(i,0,N) {cursum+=v[i]; ps.pb(cursum);}
    ll ans=0LL; ll cur; ll start=0LL; ll val;
    REP(i,0,N)
    {
        cur=P.f(i,S)-1LL;
        val=ps[cur+1]-ps[i];
        if(val>ans) {ans=val; start=i;}
    }
    cout<<S<<endl; cur=start;
    REP(i,0,S)
    {
        cout<<cen[cur]+1LL<<" ";
        cur=nxt[cur];
        if(cur>=N) {cur=N-1;}
    }
    cout<<endl;
    return 0;
}
Compilation message (stderr)
SolarStorm.cpp: In function 'void Out(std::vector<long long int>)':
SolarStorm.cpp:14:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define REP(i,a,b) for(ll i=a; i<b; i++)
SolarStorm.cpp:23:29:
 void Out(vector<ll> x) {REP(i,0,x.size()) {cout<<x[i]<<" ";} cout<<endl;}
                             ~~~~~~~~~~~~
SolarStorm.cpp:23:25: note: in expansion of macro 'REP'
 void Out(vector<ll> x) {REP(i,0,x.size()) {cout<<x[i]<<" ";} cout<<endl;}
                         ^~~| # | 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... |