Problem:
Score : 100 points

Problem Statement

There are N children, numbered 1, 2, \ldots, N.

They have decided to share K candies among themselves.
Here, for each i (1 \leq i \leq N), Child i must receive between 0 and a_i candies (inclusive).
Also, no candies should be left over.

Find the number of ways for them to share candies, modulo 10^9 + 7.
Here, two ways are said to be different when there exists a child who receives a different number of candies.

Constraints

All values in input are integers.

1 \leq N \leq 100

0 \leq K \leq 10^5

0 \leq a_i \leq K

Input

Input is given from Standard Input in the following format:

N K
a_1 a_2 \ldots a_N

Output

Print the number of ways for the children to share candies, modulo 10^9 + 7.

Sample Input 1

3 4
1 2 3

Sample Output 1

5

There are five ways for the children to share candies, as follows:

(0, 1, 3)

(0, 2, 2)

(1, 0, 3)

(1, 1, 2)

(1, 2, 1)

Here, in each sequence, the i-th element represents the number of candies that Child i receives.

Sample Input 2

1 10
9

Sample Output 2

0

There may be no ways for the children to share candies.

Sample Input 3

2 0
0 0

Sample Output 3

1

There is one way for the children to share candies, as follows:

(0, 0)

Sample Input 4

4 100000
100000 100000 100000 100000

Sample Output 4

665683269

Be sure to print the answer modulo 10^9 + 7.

Solution in Rust (1.15.1) (judge verdict: Accepted)

#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( stdin . lock ( ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[allow(unused_macros)]
macro_rules ! vecs { ( $ init : expr ; $ ( $ dim : expr ) ;* ) => { vecs ! ( $ ( $ dim ) ;* => $ init ) } ; ( $ head : expr ; $ ( $ tail : expr ) ;* => $ init : expr ) => { vec ! [ vecs ! ( $ ( $ tail ) ;* => $ init ) ; $ head ] } ; ( $ head : expr => $ init : expr ) => { vec ! [ $ init ; $ head ] } ; }

fn main() {
    input! {
        n: usize, k: usize,
        a: [usize; n]
    }

    let mut dp = vecs![Co(0);n+1;k+1];
    dp[0][k] = Co(1);
    for i in 0..n {
        let cum = Cum::new(&dp[i]);
        for j in 0..dp[0].len() {
            dp[i+1][j] = cum.sum(j, std::cmp::min(j+a[i], k)+1);
        }
    }
    println!("{}", dp[n][0]);
}

#[derive(Debug)]
#[allow(dead_code)]
struct Cum {
    s: Vec<Co>,
}
#[allow(dead_code)]
impl Cum {
    fn new(a: &Vec<Co>) -> Cum {
        let mut s = vec![Co(0); a.len() + 1];
        for i in 0..a.len() {
            s[i + 1] = s[i] + a[i];
        }
        Cum { s: s }
    }
    #[doc = " [l,r)"]
    fn sum(&self, l: usize, r: usize) -> Co {
        self.s[r] - self.s[l]
    }
}

#[allow(dead_code)]
const M: i64 = 1_000_000_007;

#[allow(dead_code)]
use std::ops::*;
#[allow(dead_code)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Co(pub i64);
#[allow(dead_code)]
impl Co {
    pub fn pow(self, mut n: u64) -> Self {
        let mut a = self;
        let mut res = Co(1);
        while n > 0 {
            if n & 1 == 1 {
                res *= a;
            }
            a = a * a;
            n >>= 1;
        }
        res
    }
}
#[allow(dead_code)]
impl std::fmt::Display for Co {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}
macro_rules ! impl_from { ( $ ( $ tpe : ident ) ,* ) => { $ ( impl From <$ tpe > for Co { fn from ( value : $ tpe ) -> Self { Co ( ( value as i64 % M + M ) % M ) } } ) * } }
impl_from!(i64, u64, usize);
macro_rules ! impl_binop { ( $ op : ident ,$ atr : ident ,$ assign : ident $ ( ,$ optr : ident ) * ) => { impl $ atr for Co { fn $ assign ( & mut self , other : Self ) { * self = self .$ op ( other ) ; } } $ ( impl $ optr for Co { type Output = Self ; fn $ op ( self , other : Self ) -> Self { Co :: from ( ( self . 0 ) .$ op ( other . 0 ) ) } } ) * } }
impl_binop!(add, AddAssign, add_assign, Add);
impl_binop!(sub, SubAssign, sub_assign, Sub);
impl_binop!(mul, MulAssign, mul_assign, Mul);
impl_binop!(div, DivAssign, div_assign);
#[allow(dead_code)]
impl Div for Co {
    type Output = Self;
    fn div(self, rhs: Self) -> Self {
        self * rhs.pow((M - 2) as u64)
    }
}