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;
long long a,b,c,d,e,i,j,ii,jj,zx,xc,k,T,f[2000009],F[500009],fen[500009],pas;
vector <long long> dp[500009];
map <long long, long long> m;
map <long long, long long>::iterator it;
void upd(long long q, long long w){
while(q<=a+2){
if(fen[q]>w) fen[q]=w;
q=q+(q&(-q));
}
}
long long read(long long q){
long long sm=a+3;
while(q>=1){
if(sm>fen[q]) sm=fen[q];
q=q-(q&(-q));
}
return sm;
}
int main(){
ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>a>>k>>T;pas=a+3;
for(i=1; i<=a; i++){
cin>>f[i];
}
for(i=0; i<=a+1; i++){
dp[i].resize(k+3);
}
for(i=0; i<=a+1; i++){
for(j=0; j<=k+1; j++){
dp[i][j]=a+3;
}
}
for(i=1; i<=a; i++){
m[f[i]-i]=1;
}
m[-1010000002]=1;zx=0;
for(it=m.begin(); it!=m.end(); it++){
zx++;
(*it).second=zx;
}
for(i=1; i<=a; i++) F[i]=m[f[i]-i];
F[a+1]=m[-1010000002];
/*for(i=1; i<=a; i++){
zx=0;c=f[i];
for(ii=i; ii<=a; ii++){
xc=(min(f[ii],c+1)<=T);
zx+=xc;
c=min(f[ii],c+1);
}
dp[i][0]=zx;
}*/
for(i=0; i<=a+2; i++){
fen[i]=a+3;
}
dp[a+1][0]=0;
upd(F[a+1],a+1);
for(i=a; i>=1; i--){
j=read(F[i]);
dp[i][0]=dp[j][0];
j--;
//dp[i][0]+=max(0LL,min(f[i]+(j-i)-T+1,j-i+1));
dp[i][0]+=max(0LL,min(T-f[i]+1,j-i+1));
upd(F[i],i);
//cout<<i<<" "<<j<<" "<<dp[i][0]<<endl;
}
if(k==1){
zx=0;c=f[1];
for(ii=1; ii<a; ii++){
xc=(min(f[ii],c+1)<=T);
zx+=xc;
pas=min(pas,zx+dp[ii+1][0]);
c=min(f[ii],c+1);
}
cout<<pas;
return 0;
}
return 0;
for(i=a; i>=1; i--){
for(j=1; j<=k; j++){
zx=0;c=f[i];
for(ii=i; ii<=a; ii++){
xc=(min(f[ii],c+1)<=T);
zx+=xc;
e=dp[ii+1][j-1]+zx;
if(dp[i][j]>e) dp[i][j]=e;
c=min(c+1,f[ii]);
}
}
}
cout<<dp[1][k];
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... |