Skip to content

Instantly share code, notes, and snippets.

@wasabili
Created October 28, 2010 08:35
Show Gist options
  • Save wasabili/650920 to your computer and use it in GitHub Desktop.
Save wasabili/650920 to your computer and use it in GitHub Desktop.
Stairs
#include <cstdio>
#include <cstring>
int diffs[500001];
int a[500002];
main(){
int n,power;
scanf("%d%d",&n,&power);
memset(a,0,sizeof(a));
for(int i=0;i<n;i++) scanf("%d", diffs+i);
int len = 0;
int top = 0;
int bottom = 0;
int num = 0;
a[0] = 1;
for(;top < n;top++){
num += a[top];
len += diffs[top];
for(;len > power; len-=diffs[bottom],num-=a[bottom],++bottom);
a[top+1] = num = num%1234567;
}
if(a[n]<0) a[n]+=1234567;
printf("%d\n", a[n]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment