Submission #285490

#TimeUsernameProblemLanguageResultExecution timeMemory
285490achibasadzishviliSolar Storm (NOI20_solarstorm)C++17
36 / 100
573 ms146272 KiB
#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];
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){
    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;
    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++;
        p[i] = max(l - 1 , 0LL);
        if(l == 0)o[i] = 0;
        else
            o[i] = p[p[i]] + 1;
        q[i] += v[r] - v[l - 1];
      //  cout << i << " -- " << o[i] << '\n';
    }
    
    for(int i=1; i<=n; i++){
        P[i][0] = o[i];
        sum[i] = sum[o[i]] + q[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);
        //cout << i << " " << mx << '\n';
        if(mx >= ans){
            ans = mx;
            ind = i;
        }
    }
    
    vector<ll>an;
    
    while(ind != 0 && an.size() < s){
        an.pb(ind);
        ind = o[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 '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 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...