Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
a = tuple(map(int, input().split()))

def main():
    l = [1 if a[0] >= j else 0 for j in range(K+1)]
    lt= [1 if a[0] >= j else 0 for j in range(K+1)]
    s = a[0]
    for i in range(1,N):
        lt, l = l, lt
        s += a[i]
        l[0] = 1
        t = 1
        for j in range(1, a[i]+1):
                t += lt[j]
                l[j] = t
        for j in range(a[i]+1, min(K+1, s+1)):
                t += (lt[j] - lt[j - a[i] - 1])
                l[j] = t
    return l[-1] % (10 ** 9 + 7)
            
print(main())


Fixed submission:
N, K = map(int, input().split())
a = tuple(map(int, input().split()))

def main():
    l = [1 if a[0] >= j else 0 for j in range(K+1)]
    lt= [0] * (K+1)
    s = a[0]
    for i in range(1,N):
        lt, l = l, lt
        s += a[i]
        l[0] = 1
        t = 1
        for j in range(1, a[i]+1):
                t += lt[j]
                l[j] = t
        for j in range(a[i]+1, min(K+1, s+1)):
                t += (lt[j] - lt[j - a[i] - 1])
                l[j] = t
    return l[-1] % (10 ** 9 + 7)
            
print(main())

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
a = tuple(map(int, input().split()))

def main():
    l = [1 if a[0] >= j else 0 for j in range(K+1)]
    s = a[0]
    for i in range(1,N):
        lt = l
        l = [0] * (K + 1)
        s += a[i]
        l[0] = 1
        t = 1
        for j in range(1, a[i]+1):
                t += lt[j]
                l[j] += t
        for j in range(a[i]+1, min(K+1, s+1)):
                t += (lt[j] - lt[j - a[i] - 1])
                l[j] += t
    return l[-1] % (10 ** 9 + 7)
            
print(main())


Fixed submission:
N, K = map(int, input().split())
a = tuple(map(int, input().split()))

def main():
    l = [1 if a[0] >= j else 0 for j in range(K+1)]
    lt= [0] * (K+1)
    s = a[0]
    for i in range(1,N):
        lt, l = l, lt
        s += a[i]
        l[0] = 1
        t = 1
        for j in range(1, a[i]+1):
                t += lt[j]
                l[j] = t
        for j in range(a[i]+1, min(K+1, s+1)):
                t += (lt[j] - lt[j - a[i] - 1])
                l[j] = t
    return l[-1] % (10 ** 9 + 7)
            
print(main())

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
a = tuple(map(int, input().split()))

def main():
    l = [1 if a[0] >= j else 0 for j in range(K+1)]
    s = a[0]
    for i in range(1,N):
        t = 0
        lt = l
        l = [0] * (K + 1)
        s += a[i]
        for j in range(min(K+1, s+1)):
            if j == 0:
                t = 1
                l[j] = 1
            else:
                if j <= a[i]:
                    t += lt[j]
                else:
                    t += (lt[j] - lt[j - a[i] - 1])
                l[j] += t
    return l[-1] % (10 ** 9 + 7)
            
print(main())


Fixed submission:
N, K = map(int, input().split())
a = tuple(map(int, input().split()))

def main():
    l = [1 if a[0] >= j else 0 for j in range(K+1)]
    lt= [0] * (K+1)
    s = a[0]
    for i in range(1,N):
        lt, l = l, lt
        s += a[i]
        l[0] = 1
        t = 1
        for j in range(1, a[i]+1):
                t += lt[j]
                l[j] = t
        for j in range(a[i]+1, min(K+1, s+1)):
                t += (lt[j] - lt[j - a[i] - 1])
                l[j] = t
    return l[-1] % (10 ** 9 + 7)
            
print(main())

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
a = tuple(map(int, input().split()))

def main():
    l = [0] * (K+1)
    for i in range(N):
        t = 0
        lt = l
        l = [0] * (K + 1)
        for j in range(K+1):
            if i == 0:
                if a[i] >= j:
                    l[j] = 1
            elif j == 0:
                t = 1
                l[j] = 1
            else:
                if j <= a[i]:
                    t += lt[j]
                else:
                    t += (lt[j] - lt[j - a[i] - 1])
                l[j] += t
    return l[-1] % (10 ** 9 + 7)
            
print(main())


Fixed submission:
N, K = map(int, input().split())
a = tuple(map(int, input().split()))

def main():
    l = [1 if a[0] >= j else 0 for j in range(K+1)]
    lt= [0] * (K+1)
    s = a[0]
    for i in range(1,N):
        lt, l = l, lt
        s += a[i]
        l[0] = 1
        t = 1
        for j in range(1, a[i]+1):
                t += lt[j]
                l[j] = t
        for j in range(a[i]+1, min(K+1, s+1)):
                t += (lt[j] - lt[j - a[i] - 1])
                l[j] = t
    return l[-1] % (10 ** 9 + 7)
            
print(main())

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
a = tuple(map(int, input().split()))

def main():
    l = [[0] * (K+1) for _ in range(N)]
    for i in range(N):
        t = 0
        for j in range(K+1):
            if i == 0:
                if a[i] >= j:
                    l[i][j] = 1
            elif j == 0:
                t = 1
                l[i][j] = 1
            else:
                if j <= a[i]:
                    t += l[i - 1][j]
                else:
                    t += (l[i - 1][j] - l[i - 1][j - a[i] - 1])
                l[i][j] += t
    return l[-1][-1] % (10 ** 9 + 7)
            
print(main())


Fixed submission:
N, K = map(int, input().split())
a = tuple(map(int, input().split()))

def main():
    l = [1 if a[0] >= j else 0 for j in range(K+1)]
    lt= [0] * (K+1)
    s = a[0]
    for i in range(1,N):
        lt, l = l, lt
        s += a[i]
        l[0] = 1
        t = 1
        for j in range(1, a[i]+1):
                t += lt[j]
                l[j] = t
        for j in range(a[i]+1, min(K+1, s+1)):
                t += (lt[j] - lt[j - a[i] - 1])
                l[j] = t
    return l[-1] % (10 ** 9 + 7)
            
print(main())

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
a = tuple(map(int, input().split()))

def main():
    l = [[0] * (K+1) for _ in range(N)]
    for i in range(N):
        t = 0
        for j in range(K+1):
            if i == 0:
                if a[i] >= j:
                    l[i][j] = 1
            elif j == 0:
                t = 1
                l[i][j] = 1
            else:
                if j <= a[i]:
                    t += l[i - 1][j]
                else:
                    t += (l[i - 1][j] - l[i - 1][j - a[i] - 1])
                l[i][j] += t
    return l[-1][-1] % (10 ** 9 + 7)
            
print(main())


Fixed submission:
N, K = map(int, input().split())
a = tuple(map(int, input().split()))

def main():
    l = [1 if a[0] >= j else 0 for j in range(K+1)]
    lt= [0] * (K+1)
    s = a[0]
    for i in range(1,N):
        lt, l = l, lt
        s += a[i]
        l[0] = 1
        t = 1
        for j in range(1, a[i]+1):
                t += lt[j]
                l[j] = t
        for j in range(a[i]+1, min(K+1, s+1)):
                t += (lt[j] - lt[j - a[i] - 1])
                l[j] = t
    return l[-1] % (10 ** 9 + 7)
            
print(main())