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 C++ (GCC 9.2.1) (judge verdict: Wrong Answer)

#include<bits/stdc++.h>
using namespace std;

#define endl "\n"
#define ll long long int
#define f(i,st,ed) for(ll i=st;i<ed;i++)
#define fr(i,ed,st) for(ll i=ed;i>=st;i--)
#define vv vector<ll>
#define all(v) v.begin(),v.end() 
#define pb push_back
#define pp pair<ll,ll>
#define gv(v,s,e) f(i,s,e){ ll x; cin >> x; v.pb(x);}
#define pv(v,s,e) f(i,s,e){cout << v[i] << " ";}
#define MOD 1000000007
#define debug(x) cout << x << endl;


void yes(){
    cout << "YES" << endl;
}

void no(){
    cout << "NO" << endl;
}

ll powmod(ll x, ll y, ll mod)
{
    ll ans=1;

    while(y)
    {
        if(y%2==1)
        {
            ans = (ans*x)%mod;
        }

        x = (x*x)%mod;
        y/=2;
    }

    return ans;
}

ll dp[105][100005];
ll pre[105][100005];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll n,k;
    cin >> n >> k;

    vv v;
    gv(v,0,n);

    dp[0][0]=1;
    pre[0][0]=1;

    f(i,1,n+5)
    {
        dp[i][0]=1;
        pre[i][0]=1;
    }

    f(i,1,k+5)
    {
        dp[0][i]=0;
        pre[0][i]=0;
    }
    

    f(i,1,n+1)
    {
        ll x = v[i-1];

        f(j,1,k+5)
        {
            pre[i-1][j] = (pre[i-1][j-1]+dp[i-1][j])%MOD;
        }

        f(j,0,k+5)
        {
            if(j-x-1<0)
                dp[i][j] = pre[i-1][j]%MOD;
            else
                dp[i][j] = (pre[i-1][j]-pre[i-1][j-x-1])%MOD;
        }
    }

//    f(i,0,5)
//    {
//        f(j,0,5)
//        {
//            cout << dp[i][j] << " ";
//        }
//        cout << endl;
//    }
    cout << dp[n][k] << " ";

    return 0;
}