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>
#define ll long long
#define f first
#define s second
#define pb push_back
using namespace std;
ll a[1000003],p[1000003],q[1000003],w[1000003];
int P[1000003][21];
ll sum[1000003],mx,o[1000003];
ll n,m,k,s,v[1000003],ans,ind;
ll get(ll x,ll y){
    ll val = 0;
    for(int j=20; j>=0; j--)
        if(y >= (1 << j)){
            y -= (1 << j);
            x = P[x][j];
        }
    return -sum[x];
}
int main(){
    ios::sync_with_stdio(false);
    cin >> n >> s >> k;
    for(int i=2; i<=n; i++){
        cin >> a[i];
        a[i] += a[i - 1];
    }
    
    for(int i=1; i<=n; i++){
        cin >> v[i];
        v[i] += v[i - 1];
    }
    
    ll l = 0,r = 0,wr = 0;
    a[0] = 0;
    for(int i=1; i<=n; i++){
        while(a[i] - a[l] > k)l++;
        while(r < n && a[r + 1] - a[i] <= k)r++;
        for(int j=max(1LL,wr + 1); j<=r; j++){
            p[j] = max(l - 1 , 0LL);
            q[j] = v[r] - v[max(l - 1,0LL)];
            sum[j] = sum[max(l - 1,0LL)] + v[j] - v[l - 1];
            w[j] = i;
        }
        wr = r;
    }
    
    for(int i=1; i<=n; i++){
        P[i][0] = p[i];
        for(int j=1; j<=20; j++)
            P[i][j] = P[P[i][j - 1]][j - 1];
        ll mx = sum[i] + get(i , s);
        if(mx >= ans){
            ans = mx;
            ind = i;
        }
    }
    
    vector<ll>an;
    
    while(ind != 0 && an.size() < s){
        an.pb(w[ind]);
        ind = p[ind];
    }
    sort(an.begin() , an.end());
    cout << an.size() << '\n';
    
    for(int i=0; i<an.size(); i++)
        cout << an[i] << " ";
    
    
    return 0;
}
Compilation message (stderr)
SolarStorm.cpp: In function 'long long int get(long long int, long long int)':
SolarStorm.cpp:12:8: warning: unused variable 'val' [-Wunused-variable]
   12 |     ll val = 0;
      |        ^~~
SolarStorm.cpp: In function 'int main()':
SolarStorm.cpp:60:33: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   60 |     while(ind != 0 && an.size() < s){
      |                                 ^
SolarStorm.cpp:67:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |     for(int i=0; i<an.size(); i++)
      |                  ~^~~~~~~~~~| # | 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... |