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)

macro_rules! debug {
    ( $x:expr ) => {
        if cfg!(debug_assertions) {
            println!("{}:{} {} = {:?}", line!(), column!(), stringify!($x), $x);
        }
    }
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin = my::io::InputReader::new(stdin.lock());

    const MOD: u32 = 1_000_000_007;
    let N = stdin.read();
    let K: usize = stdin.read();
    let mut a = vec![0; N];
    for i in 0..N {
        a[i] = stdin.read();
    }

    let mut dp = vec![vec![0; K + 1]; N + 1];
    let mut dp_sum = vec![vec![0; K + 2]; N + 1];
    for i in 0..N + 1 {
        dp[i][0] = 1;
        dp_sum[i][0] = 0;
        dp_sum[i][0 + 1] = dp_sum[i][0] + dp[i][0];
    }
    for j in 1..K + 1 {
        dp[0][j] = 0;
        dp_sum[0][j + 1] = dp_sum[0][j] + dp[0][j];
    }
    
    for i in 1..N + 1 {
        for j in 1..K + 1 {
            /*
            for k in 0..std::cmp::min(j, a[i - 1]) + 1 {
                dp[i][j] = (dp[i][j] + dp[i - 1][j - k]) % MOD;
            }
            */

            let l = if j >= a[i - 1] {
                j - a[i - 1]
            } else {
                0
            };
            /*
            for k in l..j + 1 {
                dp[i][j] = (dp[i][j] + dp[i - 1][k]) % MOD;
            }
            */

            dp[i][j] = (dp_sum[i - 1][j + 1] + (MOD - dp_sum[i - 1][l])) % MOD;
            dp_sum[i][j + 1] = (dp_sum[i][j] + dp[i][j]) % MOD;
            //println!("dp[{}][{}] = {}", i, j, dp[i][j]);
            //println!("dp_sum[{}][{}] = {}", i, j + 1, dp_sum[i][j + 1]);
        }
    }
    println!("{}", dp[N][K]);
}

mod my {
    pub mod io {
        use std::io::{BufRead, ErrorKind, Result};
        use std::str::{FromStr, from_utf8};
        use std::fmt::Debug;

        pub fn read_word<R: BufRead>(r: &mut R, buf: &mut Vec<u8>)
                                              -> Result<usize> {
            let mut read = 0;
            loop {
                let (done, used) = {
                    let available = match r.fill_buf() {
                        Ok(n) => n,
                        Err(ref e) if e.kind() == ErrorKind::Interrupted => continue,
                        Err(e) => return Err(e)
                    };
                    match available.iter().position(|&x| x == b'\n' || x == b' ') {
                        Some(i) => {
                            buf.extend_from_slice(&available[..i]);
                            (true, i + 1)
                        }
                        None => {
                            buf.extend_from_slice(available);
                            (false, available.len())
                        }
                    }
                };
                r.consume(used);
                read += used;
                if done || used == 0 {
                    return Ok(read);
                }
            }
        }

        pub struct InputReader<R: BufRead> {
            reader: R,
            buf: Vec<u8>,
        }

        impl<R: BufRead> InputReader<R> {
            pub fn new(reader: R) -> InputReader<R> {
                InputReader {
                    reader: reader,
                    buf: Vec::<u8>::new(),
                }
            }

            pub fn read_word(&mut self) {
                read_word(&mut self.reader, &mut self.buf);
            }
            
            pub fn read<T>(&mut self) -> T
                where T: FromStr,
                      T::Err: Debug
            {
                self.buf.clear();
                self.read_word();
                from_utf8(&self.buf).unwrap().trim().parse().unwrap()
            }
        }
    }
}