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 int long long
using namespace std;
const int N=1000006;
int n,s,d;
int a[N],v[N],pref[N],p[N],gr[N],par[N];
vector<int> b,g[N];
deque<int> q;
void DFS(int v,int pr){
q.push_back(v);
int pos=max(0LL,(int)q.size()-(int)s-1LL);
gr[v]=max(q[pos],0LL);
par[v]=pr;
for(auto to : g[v]){
if(pr==to)
continue;
DFS(to,v);
}
q.pop_back();
}
main(){
cin>>n>>s>>d;
b.push_back(0);
for(int k=2;k<=n;k++){
cin>>a[k];
p[k]=p[k-1]+a[k];
b.push_back(p[k]);
}
for(int k=1;k<=n;k++){
cin>>v[k];
pref[k]=pref[k-1]+v[k];
}
for(int k=1;k<=n;k++){
int l=lower_bound(b.begin(),b.end(),p[k]-d)-b.begin();
int ll=lower_bound(b.begin(),b.end(),p[l+1]-d)-b.begin();
g[ll].push_back(k);
}
DFS(0,0);
int st=0,mx=0;
for(int k=1;k<=n;k++){;
if(mx<pref[k]-pref[gr[k]]){
mx=pref[k]-pref[gr[k]];
st=k;
}
}
vector<int> ans;
int m=s;
while(m){
int l=lower_bound(b.begin(),b.end(),p[st]-d)-b.begin()+1;
ans.push_back(l);
st=par[st];
m--;
}
cout<<ans.size()<<endl;
sort(ans.begin(),ans.end());
for(auto i : ans)
cout<<i<<' ';
return 0;
}
Compilation message (stderr)
SolarStorm.cpp:21:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
21 | main(){
| ^
# | 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... |