이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int MAX=1000005;
const int LOG=21;
int n, s, lf[MAX], rg[MAX], par[LOG][MAX];
ll k, d[MAX], v[MAX], ans;
vector<int>ansv;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin>>n>>s>>k;
for(int i=2; i<=n; i++){
cin>>d[i];
d[i]+=d[i-1];
}
for(int i=1; i<=n; i++){
cin>>v[i];
v[i]+=v[i-1];
}
rg[0]=1;
for(int i=1, l=1, r=1, x=0; i<=n; i++){
for(; r<=n && d[r]<=d[i]+k; r++);
for(; l<=n && d[l]<d[i]-k; l++);
for(; rg[x]<l; x++);
lf[i]=l; rg[i]=r;
par[0][i]=x;
}
for(int lg=1; lg<LOG; lg++)
for(int i=1; i<=n; i++)
par[lg][i]=par[lg-1][par[lg-1][i]];
int pos=0;
for(int i=1; i<=n; i++){
int nw=i;
for(int lg=0; lg<LOG; lg++)
if(((s-1)>>lg)&1) nw=par[lg][nw];
ll tmp=v[rg[i]-1]-v[lf[nw]-1];
if(tmp>ans){ans=tmp; pos=i;}
}
for(int i=0; i<s && pos>0; i++){
ansv.push_back(pos);
pos=par[0][pos];
}
cout<<ansv.size()<<endl;
for(int i:ansv) cout<<i<<" ";
cout<<endl;
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... |