Problem:


Score : 300 points

Problem Statement

There are N boxes arranged in a row.
Initially, the i-th box from the left contains a_i candies.

Snuke can perform the following operation any number of times:

Choose a box containing at least one candy, and eat one of the candies in the chosen box.

His objective is as follows:

Any two neighboring boxes contain at most x candies in total.

Find the minimum number of operations required to achieve the objective.

Constraints

2 ≤ N ≤ 10^5

0 ≤ a_i ≤ 10^9

0 ≤ x ≤ 10^9

Input

The input is given from Standard Input in the following format:

N x
a_1 a_2 ... a_N

Output

Print the minimum number of operations required to achieve the objective.

Sample Input 1

3 3
2 2 2

Sample Output 1

1

Eat one candy in the second box.
Then, the number of candies in each box becomes (2, 1, 2).

Sample Input 2

6 1
1 6 1 2 0 4

Sample Output 2

11

For example, eat six candies in the second box, two in the fourth box, and three in the sixth box.
Then, the number of candies in each box becomes (1, 0, 1, 0, 0, 1).

Sample Input 3

5 9
3 1 4 1 5

Sample Output 3

0

The objective is already achieved without performing operations.

Sample Input 4

2 0
5 5

Sample Output 4

10

All the candies need to be eaten.



Sample input:
3 3
2 2 2


Sample output:
1

Submission status: Wrong Answer

Solution code:
def solve():
    N, x = list(map(int, input().split(" ")))
    candies = list(map(int, input().split(" ")))
    cnt = 0

    if N % 2:
        for i in range(1, N, 2):
            if (candies[i - 1] + candies[i] > x) and (candies[i] + candies[i + 1] > x):
                cnt += max(candies[i - 1] + candies[i], candies[i] + candies[i + 1]) - x
            elif (candies[i - 1] + candies[i] > x) and (candies[i] + candies[i + 1] <= x):
                cnt += candies[i - 1] + candies[i] - x
            elif (candies[i - 1] + candies[i] <= x) and (candies[i] + candies[i + 1] > x):
                cnt += candies[i] + candies[i + 1] - x
            else:
                pass
    else:
        if N == 2:
            if sum(candies) > x:
                cnt += sum(candies) - x
        else:
            for i in range(1, N + 1, 2):
                if i == N - 1:
                    if candies[i - 1] + candies[i] > x:
                        cnt += candies[i - 1] + candies[i] - x
                    else:
                        pass
                else:
                    if (candies[i - 1] + candies[i] > x) and (candies[i] + candies[i + 1] > x):
                        cnt += max(candies[i - 1] + candies[i], candies[i] + candies[i + 1]) - x
                    elif (candies[i - 1] + candies[i] > x) and (candies[i] + candies[i + 1] <= x):
                        cnt += candies[i - 1] + candies[i] - x
                    elif (candies[i - 1] + candies[i] <= x) and (candies[i] + candies[i + 1] > x):
                        cnt += candies[i] + candies[i + 1] - x
                    else:
                        pass

    print(cnt)


solve()

Submission status: Wrong Answer

Solution code:
N,x=map(int,input().split())
S = [int(i) for i in input().split()]
pre,ans = 0,0
for i in range(N):
    tmp = pre+S[i]
    if tmp > x:
        ans += tmp-x
        S[i] -= tmp-x
        pre = S[i]
print(ans)

Submission status: Wrong Answer

Solution code:
N, x = map(int, raw_input().split())
a = map(int, raw_input().split())
ans = 0
for i in range(N-1):
    total = a[i] + a[i+1]
    if total > x:
        ans += total - x
        a[i+1] -= total - x
print ans

Submission status: Wrong Answer

Solution code:
N, x = [int(n) for n in input().split()]
a = [int(n) for n in input().split()]

res = 0
if a[0] > x:
    a[0] = x
    res += a[0] - x

for i in range(1, N):
    if a[i-1] + a[i] > x:
        res += a[i] - (x - a[i-1])
        a[i] = x - a[i-1]

print(res)

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
a = [int(i) for i in input().split()]
l = len(a)

ans = 0

for i in range(l-1):
    dif = x - a[i]
    if a[i+1] > dif:
        ans += a[i+1] - dif
        a[i+1] = dif

print(ans)

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
a = [int(i) for i in input().split()]
l = len(a)

ans = 0

for i in range(l-1):
    if a[i] + a[i+1] > x:
        dif = a[i] + a[i+1] - x
        a[i+1] = x - a[i]
        ans += dif

print(ans)

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
a = [int(i) for i in input().split()]
l = len(a)

ans = 0

for i in range(l-1):
    if a[i] + a[i+1] > x:
        dif = a[i] + a[i+1] - x
        a[i+1] -= dif
        ans += dif

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-
import math
N, x = map(int,input().split())
a = list(map(int, input().split()))
ans = 0
for tmp in range (0,N-1):
    if a[tmp] + a[tmp+1] <= x:
        continue
    else:
        tmp2 = (a[tmp]+a[tmp+1]) - x #差分を出す。
        if a[tmp+1] >= a[tmp]:
            if a[tmp+1] - tmp2 >= 0:
                a[tmp+1] -= tmp2
                ans += tmp2
            else: #足りない場合
                ans += tmp2
                a[tmp] += a[tmp+1] - tmp2 #足りない部分はa[tmp]から引く。
                tmp2 += a[tmp+1] - tmp2
                a[tmp+1] -= tmp2
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-
import math
N, x = map(int,input().split())
a = list(map(int, input().split()))
ans = 0
for tmp in range (0,N-1):
    if a[tmp] + a[tmp+1] <= x:
        continue
    else:
        tmp2 = (a[tmp]+a[tmp+1]) - x #差分を出す。
        if a[tmp+1] >= a[tmp]:
            if a[tmp+1] - tmp2 >= 0:
                a[tmp+1] -= tmp2
                ans += tmp2
            else: #足りない場合
                ans += tmp2
                a[tmp] += a[tmp+1] - tmp2 #足りない部分はa[tmp]から引く。
                tmp2 += a[tmp+1] - tmp2
                a[tmp+1] -= tmp2
        else:
            if a[tmp] - tmp2 >= 0:
                a[tmp] -= tmp2
                ans += tmp2
            else:
                ans += tmp2
                a[tmp+1] += a[tmp] - tmp2 #足りない部分はa[tmp+1]から引く。
                tmp2 += a[tmp] - tmp2
                a[tmp] -= tmp2
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-
import math
N, x = map(int,input().split())
a = list(map(int, input().split()))
ans = 0
for tmp in range (0,N-1):
    if a[tmp] + a[tmp+1] <= x:
        continue
    else:
        if a[tmp+1] > x - a[tmp]:
            tmp2 = a[tmp+1] - (x-a[tmp])
            a[tmp+1] -= tmp2
        else:
            tmp2 = a[tmp] - (x-a[tmp+1])
            a[tmp] -= tmp2
        ans += tmp2
print(ans)

Submission status: Wrong Answer

Solution code:
N, x = map(int,input().split())
a = list(map(int,input().split()))
Nc = 0
if a[0] > x:
    Nc += a[0] - x
    a[0] = x
print(Nc)
for i in range(N-1):
    if (a[i] + a[i+1] - x) > 0:
        Nc += a[i] + a[i+1] -x
        a[i+1] = x - a[i]

print(Nc)

Submission status: Wrong Answer

Solution code:
N, x = map(int,input().split())
a = list(map(int,input().split()))
Nc = 0
if a[0] > x:
    a[0] = x
    Nc += a[0] - x

for i in range(N-1):
    if (a[i] + a[i+1] - x) > 0:
        Nc += a[i] + a[i+1] -x
        a[i+1] = x - a[i]

print(Nc)

Submission status: Wrong Answer

Solution code:
N, x = map(int,input().split())
a = list(map(int,input().split()))
Nc = 0
for i in range(N):
    if a[i] > x:
        Nc = Nc + (a[i]-x)
        a[i] = x
if N>= 2:
        for i in range(1,N-1):
            B = a[1:N-1]
            j = B.index(max(B)) + 1
            Nc = Nc + max(a[j] + max(a[j-1],a[j+1]) - x, 0)
            a[j] -= max(a[j] + max(a[j-1],a[j+1]) - x, 0)
print(Nc)

Submission status: Wrong Answer

Solution code:
N, x = map(int,input().split())
a = list(map(int,input().split()))
Nc = 0
for i in range(N):
    if a[i] > x:
        Nc = Nc + (a[i]-x)
        a[i] = x
if N>= 2:
    for i in range(1,N-1):
        Nc = Nc + max(a[i] + max(a[i-1],a[i+1]) - x, 0)
        a[i] -= max(a[i] + max(a[i-1],a[i+1]) - x, 0)
print(Nc)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
a = list(map(int, input().split()))

diff = [a[i] + a[i+1] for i in range(N-1)]

counter = 0

for i in range(N-2):
    if diff[i] > x:
        counter += diff[i] - x
        diff[i+1] -= diff[i] - x
        diff[i] -= diff[i] - x
if diff[N-2] > x:
    counter += diff[N-2] - x

print(counter)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
a=list(map(int,input().split()))
ans=0

for i in range(n-1):
    overflow = a[i]+a[i+1]-x
    ans += overflow
    if a[i+1]>= overflow:
        a[i+1] -= overflow
    else:

        a[i] -= overflow -a[i+1]
        a[i+1]=0
 
print(ans)

Submission status: Wrong Answer

Solution code:
n, x = map(int, raw_input().split())
a = map(int, raw_input().split())

res = 0
if n == 0:
    print 0
    exit()
elif n == 1:
    print max(a[0] - x, 0)
    exit()

for i, e in enumerate(a):
    if i != 0:
        if e + f > x:
            res += (e + f) - x
            f = max(e - ((e + f) - x), 0)
    else:
        f = e

print res

Submission status: Wrong Answer

Solution code:
n, x = map(int, raw_input().split())
a = map(int, raw_input().split())

res = 0
for i, e in enumerate(a):
    if i != 0:
        if e + f > x:
            res += (e + f) - x
            f = max(e - ((e + f) - x), 0)
    else:
        f = e

print res

Submission status: Wrong Answer

Solution code:
N, x = map(int, raw_input().split())
A = map(int, raw_input().split())
ans = 0
for i in range(1, N):
    v = max(0, A[i-1] + A[i] - x)
    ans += v
    A[i] -= v
print ans

Submission status: Wrong Answer

Solution code:
N, x = map(int,input().split())
a_list = list(map(int,input().split()))


b_list = [a_list[i]+a_list[i+1] for i in range(0,N-1)]


excess_list = [max(0,val -x) for val in b_list]

ans = 0
for i in range(0,len(b_list)-1):
    a_val = a_list[i+1]
    b_prev = excess_list[i]
    b_next = excess_list[i+1]
    min_val = min(a_val,b_prev,b_next)
    print("prev a_list",a_list[i+1])
    a_list[i+1] -= min_val
    print("after a_list",a_list[i+1])
    excess_list[i] -= min_val
    excess_list[i+1] -= min_val
    print("i:",i,"min_val:",min_val)
    print("a_list:",a_list,"b_list:",b_list)
    ans += min_val
ans += sum(excess_list)
print(ans)

Submission status: Wrong Answer

Solution code:
#ABC048C

n,x=map(int,raw_input().split())
a=map(int,raw_input().split())
print a
res0=sum(a)
if a[0]>x:
 a[0]=x
for i in range(n-1):
 if a[i]+a[i+1]>x:
  a[i+1]=x-a[i]
  if a[i+1]<0:
   a[i+1]=0
res=res0-sum(a)
print res

Submission status: Wrong Answer

Solution code:
#003
N,x=input().split(" ")
s = input().split(" ")
list = []
for i in range(int(N)):
    list.append(int(s[i]))
count = 0
for i in range(1,int(N)):
    temp = list[i]+list[i-1]
    if(temp>int(x)):
        count+=temp-int(x)
        list[i]-=temp-int(x)        
print(count)

Submission status: Wrong Answer

Solution code:
N, x = map(int, raw_input().split())
candies = map(int, raw_input().split())
counter = 0
for i  in range(0, len(candies)-1):
    delta = candies[i+1] + candies[i] - x
    if delta > 0:
        counter += delta
        candies[i+1] = x - candies[i]
#     print x
print counter

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
a = list(map(int, input().split()))
counter = 0
pointer = 1
if a[0] > x:
    counter += x - a[0]
    a[0] = x
while pointer <= n - 1:
    if a[pointer - 1] + a[pointer] > x:
        eat = a[pointer - 1] + a[pointer] - x
        counter += eat
        a[pointer] -= eat
    pointer += 1
print(counter)

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
a = list(map(int, input().split()))
counter = 0
pointer = 1
while pointer <= n - 1:
    if a[pointer - 1] + a[pointer] > x:
        eat = a[pointer - 1] + a[pointer] - x
        counter += eat
        a[pointer] -= eat
    pointer += 1
print(counter)

Submission status: Wrong Answer

Solution code:
N, x = map(int, raw_input().split())
candies = map(int, raw_input().split())
counter = 0
for i  in range(0, len(candies)-1):
    counter += candies[i+1] + candies[i] - x
    candies[i+1] = x - candies[i]
#     print x
print counter

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
a = list(map(int, input().split()))

if sum(a) - x * (N / 2) < 0:
    print("0")
else:
    print(int(sum(a) - x * (N / 2)))

Submission status: Wrong Answer

Solution code:
N,x=map(int,input().split())
a=list(map(int,input().split()))
ans=0
for i in range(N-1):
    if a[i]+a[i+1]>x:
        buf = max(0,a[i]+a[i+1]-x)
        ans += buf
        a[i+1] -= buf

    if  a[i]+a[i+1]>x:
        
        buf = max(0,a[i]+a[i+1]-x)
        ans += buf
        a[i] -= buf

print(ans)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
a = list(map(int, input().split()))

count = 0
while(True):
    mi = a.index(max(a))
    mp = (mi+1) % len(a)
    mm = (mi-1) % len(a)
    if a[mi] + a[mp] > x:
        if a[mi] > a[mp]:
            count = count + ((a[mi] + a[mp]) - x)
            a[mi] = a[mi] - ((a[mi] + a[mp]) - x)
            print(a[mi], a[mp], x)
        else:
            count = count + ((a[mi] + a[mp]) - x)
            a[mp] = a[mp] - ((a[mi] + a[mp]) - x)

    elif a[mi] + a[mm] > x:
        if a[mi] > a[mm]:
            count = count + ((a[mi] + a[mm]) - x)
            a[mi] = a[mi] - ((a[mi] + a[mm]) - x)
        else:
            count = count + ((a[mi] + a[mm]) - x)
            a[mm] = a[mm] - ((a[mi] + a[mm]) - x)
    else:
        break
print(count)

Submission status: Wrong Answer

Solution code:

N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 0

def need_to_eat(a, i):
    return a[i] + a[i+1] > x


for i in range(N-1):
    while need_to_eat(a, i):
        a[i] -= 1
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
num_list = [int(x) for x in input().split()]
count = 0

for i in range(N-1):
  n = num_list[i] + num_list[i+1]
  if n > x:
    count += n - x
    num_list[i+1] -= (n-x)

print(count)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
a = input().split()
count = 0
for i in range(len(a)):
      a[i] = int(a[i])
      if a[i] > x:
            count = count + a[i] - x
            a[i] = x

for i in range(len(a)-1):
      if i%2 == 0:
            if a[i] + a[i + 1] > x:
                  count = count + a[i] + a[i + 1] - x
                  a[i+1] = x - a[i]
      else:
            if a[i] + a[i + 1] > x:
                  count = count + a[i] + a[i + 1] - x
                  a[i] = x - a[i + 1]
print(count)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
num_list = [int(x) for x in input().split()]
count = 0
if x == 0:
  print(100000)
else:
  for i, num in enumerate(num_list[0:-1]):
    if (num_list[i] + num_list[i+1] > x):
      if num_list[i+1] != 0:
        count+=int(num_list[i+1] - (x - num_list[i]))
        num_list[i+1] = x - num_list[i]
        if num_list[i+1] == 0:
          num_list[i+1] = 0
  print(count)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
num_list = [int(x) for x in input().split()]
count = 0
if x == 0:
  print(sum(num_list))
else:
  for i, num in enumerate(num_list[0:-1]):
    if (num_list[i] + num_list[i+1] > x):
      if num_list[i+1] != 0:
        count+=int(num_list[i+1] - (x - num_list[i]))
        num_list[i+1] = x - num_list[i]
        if num_list[i+1] == 0:
          num_list[i+1] = 0
  print(count)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
num_list = [int(x) for x in input().split()]
count = 0
if x == 0:
  print(sum(num_list))
else:
  for i, num in enumerate(num_list[0:-1]):
    if (num_list[i] + num_list[i+1] > x):
      if num_list[i+1] != 0:
        count+=int(num_list[i+1] - (x - num_list[i]))
        num_list[i+1] = x - num_list[i]
  print(count)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
num_list = [int(x) for x in input().split()]
count = 0
if x == 0:
  print(sum(num_list))
else:
  while True:
    mark = 0
    for i, num in enumerate(num_list[0:-1]):
      if (num_list[i] + num_list[i+1] > x):
        if num_list[i+1] != 0:
          count+=int(num_list[i+1] - (x - num_list[i]))
          num_list[i+1] = x - num_list[i]
          mark = 1
    if mark == 0:
      break
 
  print(count)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
num_list = [int(x) for x in input().split()]
count = 0
if x == 0:
  print(sum(num_list))
else:
  while True:
    mark = 0
    for i, num in enumerate(num_list[0:-1]):
      if (num_list[i] + num_list[i+1] > x):
        if num_list[i+1] != 0:
          num_list[i+1] = x - num_list[i]
          count+=x-num_list[i]
          mark = 1
    if mark == 0:
      break
 
  print(count)

Submission status: Wrong Answer

Solution code:
st = input().split()
N = int(st[0])
x = int(st[1])
A = input().split()
a = []
for i in range(N):
     a.append(int(A[i]))   
a.append(0)
a.append(0)
ret = 0
for i in range(N):
    if a[i] + a[i + 1] > x and a[i+1] + a[i+2] > x:
        d1 = (a[i] + a[i + 1]) - x
        d2 = (a[i+1] + a[i+2]) - x
        d = max(d1,d2,0);
        ret += min(a[i+1],d)
        a[i+1] -= min(a[i+1],d)
        d1 = max((a[i] + a[i + 1]) - x,0)
        d2 = max((a[i+1] + a[i+2]) - x,0)
        ret += min(d1,a[i])+min(d2,a[i+2])
        a[i] -= min(d1,a[i])
        a[i+2] -= min(d2,a[i+2])
    elif a[i] + a[i + 1] > x :
        d1 = max((a[i] + a[i + 1]) - x,0)
        ret +=  min(a[i+1],d1)
        a[i+1] -=  min(a[i+1],d1)
        d1 = max((a[i] + a[i + 1]) - x,0)
        ret +=  min(a[i],d1)
        a[i] -=  min(a[i],d1)
print(ret)

Submission status: Wrong Answer

Solution code:
st = input().split()
N = int(st[0])
x = int(st[1])
A = input().split()
a = []
for i in range(N):
     a.append(int(A[i]))   
a.append(0)
a.append(0)
ret = 0
for i in range(N):
    if a[i] + a[i + 1] > x and a[i+1] + a[i+2] > x:
        d1 = (a[i] + a[i + 1]) - x
        d2 = (a[i+1] + a[i+2]) - x
        d = max(d1,d2,0);
        ret += min(a[i+1],d)
        a[i+1] -= min(a[i+1],d)
        d1 = max((a[i] + a[i + 1]) - x,0)
        d2 = max((a[i+1] + a[i+2]) - x,0)
        ret += min(d1,a[i])+min(d2,a[i+2])
        a[i] -= min(d1,a[i])
        a[i+2] -= min(d2,a[i+2])
    elif a[i] + a[i + 1] > x :
        d1 = (a[i] + a[i + 1]) - x
        ret +=  min(a[i],d1)
        a[i] -=  min(a[i],d1)
        d1 = max((a[i] + a[i + 1]) - x,0)
        ret +=  min(a[i+1],d1)
        a[i+1] -=  min(a[i+1],d1)
print(ret)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, x = map(int, input().split())
a = np.array((list(map(int, input().split()))), np.int32)
if x == 0:
    print(a.sum())
else:
    n = 0
    n += np.sum(a[a >= x] - x)
    a[a >= x] = x
    if len(a) % 2 == 0:
        b = a[::2]
    else:
        b = a[:-1:2]
    c = a[1::2]
    a = b + c
    n += np.sum(a[a >= x] - x)
    print(n)

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().strip().split())
cs = list(map(int, input().strip().split()))
sums = [cs[i]+cs[i+1] for i in range(len(cs)-1)]
cnt = 0
for i in range(len(sums)-1):
	if sums[i] > x:
		tmp = sums[i] - x
		cnt += tmp
		sums[i+1] -= tmp
if sums[i+1] > x:
	cnt += sums[i+1] - x
print(cnt)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
a = list(map(int, input().split()))
b = [a[i] + a[i+1] for i in range(len(a)-1)]

cnt = 0
for i in range(len(b)):
    inc = b[i] - x
    if inc > 0:
        cnt += inc
        b[i] = x
        if i + 1 < len(b):
            b[i+1] = max(0, b[i+1]-inc)
print(cnt)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
a=[int(i) for i in input().split()]
a.append(0)
cnt=0
for i in range(1,n,2):
    MAX=max(a[i-1]+a[i],a[i]+a[i+1])
    if MAX>x:
        cnt+=MAX-x
print(cnt)

Submission status: Wrong Answer

Solution code:
s=input().split()
n=int(s[0])
x=int(s[1])
s=input().split()
ans=max(0,int(s[0])+int(s[1])-x)
prev=max(0,int(s[1])-ans)
for i in range(2,len(s)):
 now=max(0,int(s[i])+prev-x)
 ans+=now
 prev=now
print(ans)

Submission status: Wrong Answer

Solution code:
s=input().split()
n=int(s[0])
x=int(s[1])
s=input().split()
ans=max(0,int(s[0])+int(s[1])-x)
prev=int(s[1])-ans
for i in range(2,len(s)):
 now=max(0,int(s[i])+prev-x)
 ans+=now
 prev=int(s[i])-now
print(ans)

Submission status: Wrong Answer

Solution code:
st = input().split()
N = int(st[0])
x = int(st[1])
A = input().split()
a = []
for i in range(N):
     a.append(int(A[i]))   
a.append(0)
a.append(0)
ret = 0
for i in range(N):
    if a[i] + a[i + 1] > x and a[i+1] + a[i+2] > x:
        d1 = (a[i] + a[i + 1]) - x
        d2 = (a[i+1] + a[i+2]) - x
        cnt = max(d1,d2);
        a[i+1] -= max(cnt,0)
        ret += max(cnt,0)
        d1 = (a[i] + a[i + 1]) - x
        d2 = (a[i+1] + a[i+2]) - x
        a[i] -= max(d1,0)
        a[i+2] -= max(d2,0)
        ret += max(d1,0) + max(d2,0)

print(ret)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, x = map(int, input().split())
a = np.array((list(map(int, input().split()))), np.int32)
if x == 0:
    print(a.sum())
else:
    n = 0
    n += np.sum(a[a >= x] - x)
    a[a >= x] = x
    for i in range(N-1):
        if a[i] + a[i + 1] > x:
            a[i + 1] -= 1
            n += 1
    print(n)

Submission status: Wrong Answer

Solution code:
ini=map(int, raw_input().split())
box=map(int, raw_input().split())

time=0

for i in range(ini[0]-1):
	if box[i]+box[i+1]>ini[1]:
		time+=box[i]+box[i+1]-ini[1]
		box[i+1]-=time
		if box[i+1]<0:
			box[i]+=box[i+1]
			box[i+1]=0

print time

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-

l = list(map(int, input().split()))
a = list(map(int, input().split()))

num = 0
f = True
while(f):
    f = False
    for i in range(l[0]-1):
        if((a[i] + a[i+1]) > l[1]):
            f = True
            sub = (a[i] + a[i+1]) - l[1]
            a[i+1] -= sub
            num += sub
print(num)

Submission status: Wrong Answer

Solution code:
#C
N, x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

eat = 0
over = 0
for i in range(N-1):
    over = a[i]+a[i+1]-x
    if over < 0:
        over = 0
    eat, a[i+1] = eat + over, a[i+1]-over
print(eat)

Submission status: Wrong Answer

Solution code:
N, x = map(int, raw_input().split())
a = map(int, raw_input().split())

ans = 0

for i in xrange(len(a)-1):
    if sum(a[i:i+2]) > x:
        ans += (sum(a[i:i+2]) - x)
        a[i+1] -= (sum(a[i:i+2]) - x)

print ans

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

n, x = [int(w) for w in raw_input().split()]
a = [int(w) for w in raw_input().split()]

b = [a[i] + a[i+1] for i in xrange(n - 1)]

ans = 0
for i in xrange(n - 1):
    if b[i] > x:
        d = b[i] - x
        ans += d
        b[i] = x
        if i < n - 2:
            b[i + 1] = b[i + 1] - d

print ans

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
a = [int(i) for i in input().split()]

count = 0
for i in range(n-1):
    if sum(a[i:i+2]) > x:
        count += sum(a[i:i+2]) - x
        a[i+1] -= (sum(a[i:i+2]) - x)
        if sum(a[i:i+2]) > x:
            count += sum(a[i:i+2]) - x
            a[i] -= (sum(a[i:i+2]) - x)

print(count)

Submission status: Wrong Answer

Solution code:
#coding:utf-8
import math
import string
import time
import fractions

n, x = map(int,raw_input().split())
a = map(int,raw_input().split())

ans = 0
for i in range(len(a) - 1):
	if a[i] + a[i + 1] > x:
		kosuu = x - (a[i] + a[i + 1])
		if a[i+1] >= kosuu:
			a[i+1] -= kosuu
		else:
			a[i] = a[i] - (kosuu-a[i+1])
			a[i+1] = 0
		ans += kosuu

Submission status: Wrong Answer

Solution code:
N,x=map(int,raw_input().split())
a=map(int,raw_input().split())
ans=0
for looking in range(1,len(a)):
    calc=a[looking]+a[looking-1]
    if calc<=x:
        continue
    sa=calc-x
    if sa<=a[looking]:
        a[looking]-=sa
        ans+=sa
    else:
        a[looking]-=sa
        ans+=sa
        calc=a[looking]+a[looking-1]
        sa=calc-x
        a[looking-1]-=sa
        ans+=sa
print ans

Submission status: Time Limit Exceeded

Solution code:
n, x = map(int, input().split())
a = list(map(int, input().split()))
count = 0
for i in range(n-1):
    while a[i] + a[i+1] > x:
        a[i+1] -= 1
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N,X = map(int, input().split())

A = list(map(int, input().split()))
cnt = 0

for i in range(N-1):
    if A[i]+A[i+1] <= X:
        continue
    else:
        while A[i]+A[i+1] > X:
            if A[i+1] > 0:
                A[i+1] -= 1
                cnt += 1
            if A[i+1] == 0:
                break
        while A[i]+A[i+1] > X:
            if A[i] > 0:
                A[i] -= 1
                cnt += 1
            if A[i] == 0:
                break
    
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N, x = map(int, input().split())
a = list(map(int, input().split()))

count = 0
for i in range(1, N):
    if x < a[i-1] + a[i]:
        for j in range(10**9):
            if not x < a[i-1] + a[i]:
                break
            if 0 <= a[i-1]:
                a[i] -= 1
            else:
                a[i-1] -= 1
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n,x=map(int,input().split())

a=list(map(int,input().split()))

c=0

for i in range(n-1):
    while a[i]+a[i+1]>x:
        if a[i+1]>0:
            a[i+1]-=1
        else:
            a[i]-=1
        c+=1

print(c)

Submission status: Time Limit Exceeded

Solution code:
N, x = map(int, input().split())
a = list(map(int, input().split()))

count = 0

for i, c in enumerate(a):
	try:
		j = a[i + 1]
	except IndexError:
		break

	while (a[i + 1] + c) > x:
		if (a[i + 1] + c) == x:
			break
		count += 1
		a[i + 1] -= 1
	else:
		continue

print(count)

Submission status: Time Limit Exceeded

Solution code:
n,x=map(int,input().split())
a=list(map(int,input().split()))

cnt=0
for i in range(1,n):
    v = a[i]+a[i-1]-x
    if v>0:
        cnt+=v
        while v>0:
            if a[i]>0:
                a[i]-=1
            else:
                a[i-1]-=1
            v-=1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n, x = map(int, input().split())
a = list(map(int, input().split()))

num = len(a)
ans = 0

for i in range(num - 1):
    tar = a[i] + a[i + 1]
    if (tar <= x):
        continue
    else:
        while (tar > x):
            a[i + 1] -= 1
            ans += 1
            tar = a[i] + a[i + 1]


print(ans)

Submission status: Time Limit Exceeded

Solution code:
#6問目
N, x = map(int, input().split())
a = list(map(int, input().split()))
count = 0
for i in range(N-1):
    if(a[i] + a[i+1] > x):
        while(a[i] + a[i+1] > x):
            count += 1
            a[i+1] -= 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N,x = map(int,input().split())
A = list(map(int,input().split()))
A_org = sum(A)
if A[0]>x:
	A[0]=x
for i in range(N-1):
	while A[i]+A[i+1]>x:
		A[i+1]-= 1

print(A_org-sum(A))

Submission status: Time Limit Exceeded

Solution code:
# Beginner 50 C
import copy

N, x = map(int, input().split())
A = list(map(int, input().split()))
B = copy.deepcopy(A)

for i in range(N-1):
    while A[i] + A[i+1] > x:
        if A[i+1] != 0:
        	  A[i+1] -= 1
        else:
            A[i] -= 1

cnt = sum(B) - sum(A)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#Beginner 048 C
import copy

N, x = map(int, input().split())
A = list(map(int, input().split()))

lst1 = copy.copy(A)
cnt1 = 0
for i in range(N-1):
    while lst1[i] + lst1[i+1] > x:
        lst1[i] -= 1
        cnt1 += 1

lst2 = copy.copy(A)
cnt2 = 0
for j in range(N-1):
    while lst2[j] + lst2[j+1] > x:
        lst2[j+1] -= 1
        cnt2 += 1

if cnt1 >= cnt2:
    print(cnt2)
else:
    print(cnt1)

Submission status: Time Limit Exceeded

Solution code:
N,X=map(int,input().split())
*A,=map(int,input().split())

ans=0
k=A[0]
while k>X:
    ans+=1
    A[0]-=1
    k-=1 

i=0
while i+1<=N-1:
    j=A[i]+A[i+1]
    while j>X:
        A[i+1]-=1
        j-=1
        ans+=1
    i+=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,x,*a=map(int,open(0).read().split())
ans=0
if a[0]>x:
  ans=a[0]-x
  a[0]=x
for i in range(n-1):
  while a[i+1]+a[i]>x:
    a[i+1]-=1
    ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, x = map(int, input().split())
A = input().split()
alist = []
count = 0

for i in range(N):
    a = int(A[i])
    alist.append(a)

for ii in range(N - 1):
    if alist[int(ii)] + alist[int(ii) + 1] <= x:
        pass
    else:
        while alist[int(ii)] + alist[int(ii) + 1] > x:
            if alist[int(ii) + 1] > 0:
                alist[int(ii) + 1] -= 1
                count += 1
            else:
                alist[int(ii)] -= 1
                count += 1
            
print(count)

Submission status: Time Limit Exceeded

Solution code:
N,x=map(int,input().split())
a=list(map(int,input().split()))
ans=0
for i in range(N-1):
    if sum(a[i:i+2])>x:
        while sum(a[i:i+2])>x:
            a[i+1]-=1
            ans+=1
        while sum(a[i:i+2])>x:
            a[i]-=1
            ans+=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, x = map(int, input().split())
a = list(map(int, input().split()))
count = 0

for i in range(N-1):
  while a[i]+a[i+1]>x:
    if a[i]>a[i+1]:
      a[i] -= 1
      count += 1
    else:
      a[i+1] -= 1
      count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
def calc(ran, count, cans, X):
  for n in ran:
    if n == 0:
      while cans[n+1] + cans[n] > X:
        cans[n] -= 1
        count += 1  
      continue
    if n + 1 == N:
      while cans[n-1] + cans[n] > X:
        cans[n] -= 1
        count += 1  
      continue
    while cans[n-1] + cans[n] > X or cans[n+1] + cans[n] > X:
      cans[n] -= 1
      count += 1
  return count, cans

N, X = map(int, input().split())
cans = list(map(int, input().split()))

count = 0

# odd_range = range(1, N, 2)
# even_range = range(0, N, 2)
# count, cans = calc(odd_range, count, cans, X)
# count, cans = calc(even_range, count, cans, X)

# even_count = count
# print(min(odd_count, even_count))

for i in range(0, N-1):
  while cans[i] + cans[i+1] > X:
    cans[i+1] -= 1
    count += 1
print(count)