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>
#define ll 				long long
#define ld 				long double
#define fastio 			ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define debug(x) 		cerr<<#x<<" "<<x<<endl
#define cina(a,n) 		for(ll i = 0;i<n;i++)	cin>>a[i];
#define couta(a,n) 		for(ll i = 0;i<n;i++) cout<<a[i]<<" ";
#define fauto(ar)		for(auto x : ar)	cout<<x<<" ";
#define mod 			1000000007
#define inf				10010010010010010
#define siz 			100005
#define f 				first
#define s 				second
#define pb 				push_back
#define endl 			"\n"
#define ci 				cin.ignore()
using namespace std;
//ll getans(ll *a,ll n,ll k,ll pos,ll sum)
//{
//	if(sum > k)
//	return 0;
//	if(pos == n)
//	{
//		return sum == k;
//	}
//	if(dp[pos][sum] != -1)
//	return dp[pos][sum];
//	
//	ll ans = 0;
//	for(ll i = 0;i<=a[pos];i++)
//	ans += getans(a,n,k,pos+1,sum+i),
//	ans %= mod;
//	
//	return dp[pos][sum] = ans;
//	
//}
int main()
{
	ll n,k,i,j,p,flag;
	cin>>n>>k;
	ll a[n+1];
	for(i = 1;i<=n;i++)	cin>>a[i];
	
	ll dp[2][k+1];
	
	for(i = 0;i<=1;i++)
		for(j = 0;j<=k;j++)
			dp[i][j] = 0;
	
//	for(i = 0;i<=k;i++)
//	dp[0][i] = 1;
	
	ll sum[k+1];
	flag = 1;
	for(i = 1;i<=n;i++)
	{
		sum[0] = 1;
		for(j = 1;j<=k;j++)
		sum[j] = sum[j-1] + dp[flag^1][j],
		sum[j] %= mod;
		for(j = 1;j<=k;j++)
		{
			ll left = 0;
			if(j-a[i]-1 >= 0)
			left = sum[j-a[i]-1];
			
			ll right = sum[j];
			
			dp[flag][j] = right-left;
			dp[flag][j] %= mod;
			if(dp[flag][j] < 0)
			dp[flag][j] += mod;
		}	
		flag ^= 1;
	}
	
	cout<<dp[flag^1][k];
	
	
}