# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
211485 | mayhoubsaleh | Solar Storm (NOI20_solarstorm) | C++14 | 772 ms | 195284 KiB |
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 pb push_back
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const ll inf=1e9+10;
const ll maxn=1e6+100;
ll n,s,k;
ll nxt[maxn][20],pos[maxn],pre[maxn];
ll sh[maxn];
int main()
{
IOS
cin>>n>>s>>k;
pos[1]=0;
for(ll i=2;i<=n;i++){
cin>>pos[i];
pos[i]+=pos[i-1];
}
for(ll i=1;i<=n;i++){
cin>>pre[i];
pre[i]+=pre[i-1];
//cout<<pre[i]<<' ';
}
pre[n+1]=pre[n];
for(ll i=1;i<=n;i++){
ll id=upper_bound(pos+i,pos+n+1,pos[i]+k)-pos;
id--;
sh[i]=id;
nxt[i][0]=upper_bound(pos+id,pos+n+1,pos[id]+k)-pos;
//cout<<nxt[i][0]<<' ';
}
for(ll i=1;i<20;i++){
for(ll id=1;id<=n;id++){
nxt[id][i]=nxt[nxt[id][i-1]][i-1];
if(!nxt[id][i])nxt[id][i]=n+1;
}
}
pair<ll,ll>mx={-1,-1};
for(ll l=1;l<=n;l++){
ll r=l;
for(ll i=0;i<20;i++){
if(((1<<i)&s))r=nxt[r][i];
}
//cout<<l<<' '<<r<<endl;
mx=max(mx,{pre[r-1]-pre[l-1],l});
}
vector<ll>ans;
ll l=mx.second;
while(l<=n&&s){
ans.pb(sh[l]);
l=nxt[l][0];
s--;
}
cout<<ans.size()<<endl;
for(auto x:ans)cout<<x<<' ';cout<<endl;
return 0;
}
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... |