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>
using namespace std;
#define int long long
const int N=1e6+10, LG=20;
int n, s, k, d[N], pos[N], v[N], nxt[N], nxt2[LG][N], pf[N];
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> s >> k;
for (int i=1; i<n; ++i) cin >> d[i], pos[i+1]=pos[i]+d[i];
for (int i=1; i<=n; ++i) cin >> v[i];
partial_sum(v, v+n+1, pf);
for (int i=1; i<=n; ++i){
nxt[i]=max(i, nxt[i-1]);
while (nxt[i]<n && pos[nxt[i]+1]-pos[i]<=k) ++nxt[i];
}
for (int i=1; i<=n; ++i) nxt2[0][i]=nxt[nxt[i]]+1;
for (int i=0; i<LG; ++i) nxt2[i][n+1]=n+1;
for (int lg=1; lg<LG; ++lg){
for (int i=n; i>=1; --i) nxt2[lg][i]=nxt2[lg-1][nxt2[lg-1][i]];
}
auto jump=[&](int x, int t) -> int {
t=min(t, n);
for (int i=0; i<LG; ++i) if (t>>i&1) x=nxt2[i][x];
return x;
};
pair<int, int> ans={-1, -1};
for (int i=1; i<=n; ++i){
int cur=jump(i, s);
ans=max(ans, {pf[cur-1]-pf[i-1], i});
}
vector<int> res;
int cur=ans.second, cnt=s;
while (cur!=n+1 && cnt--){
res.push_back(nxt[cur]);
cur=nxt[nxt[cur]]+1;
}
cout << res.size() << '\n';
for (int i:res) cout << i << ' ';
return 0;
}
# | 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... |