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:
N,x=map(int,input().split())
a=list(map(int,input().split()))
cnt=0
flag=False
for i in range(N):
    if i%2==1:
        if a[i-1]+a[i]>x:
            if a[i-1]<=x:
                tmp=a[i]
                a[i]=x-a[i-1]
                cnt+=tmp-a[i]
            elif a[i-1]>x:
                tmp=a[i]
                a[i]=0
                cnt+=tmp

for i in range(N-1):
    if i%2==0:
        if a[i]+a[i+1]>x:
            tmp=a[i]
            a[i]=x-a[i+1]
            cnt+=tmp-a[i]

print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
A = list(map(int, input().split()))
print(sum(A)-(sum(min(x, a1+a2) for a1, a2 in zip(A, A[1:]))+min(A[0],x)+min(A[-1],x))//2)

Submission status: Wrong Answer

Solution code:
N,x=map(int,input().split())
A=list(map(int,input().split()))
cnt=0
for i in range(N):
  cnt+=max(A[i]-x,0)
  A[i]=min(A[i],x)
for i in range(1,N):
  d=max(A[i]+A[i-1]-x,0)
  A[i]-=d
  cnt+=d
print(cnt,A)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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):
    w=a[i]+a[i+1]
    if w > x:
        a[i+1]-=(w-x)
        ans+=(w-x)
print(ans)

Submission status: Wrong Answer

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

count = 0
if cList[0] > x:
  cList[0] = x
  count += cList[0]- x

for i in range(1,n):
  tmp = cList[i-1]+cList[i]-x
  if tmp > 0:
    cList[i] -= tmp
    count += tmp

print(count)

Submission status: Wrong Answer

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

count = 0
if cList[0] > x:
  cList[0] = x
  count += x

for i in range(1,n):
  tmp = cList[i-1]+cList[i]-x
  if tmp > 0:
    cList[i] -= tmp
    count += tmp

print(count)

Submission status: Wrong Answer

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

count = 0
for i in range(1,n):
  tmp = cList[i-1]+cList[i]-x
  if tmp > 0:
    cList[i] -= tmp
    count += tmp

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n,x=map(int,input().split())
a=list(map(int,input().split()))
ans=0
if a[0]>x:
    ans+=a[0]-x
for i in range(1,n):
    if a[i]+a[i-1]>x:
        ans+=a[i]-(x-a[i-1])
        a[i]=x-a[i-1]
#print(a)
print(ans)

Submission status: Wrong Answer

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

ans = 0
if A[0] > x:
    ans += A[0] -x

for i in range(N-1):
    if A[i] + A[i+1] > x:
        ans += A[i] + A[i+1] - x
        A[i+1] -= A[i] + A[i+1] - x

print(ans)

Submission status: Wrong Answer

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

ans = 0
for i in range(1, n):
    if a[i-1] + a[i] > x:
        diff = (a[i-1] + a[i]) - x
        ans += diff
        a[i] -= diff
print(ans)

Submission status: Wrong Answer

Solution code:
#48c
N,x = map(int, input().split())
a_list = [int(e) for e in input().split()]

ans = 0

for i in range(N-1):
    #print(a_list)
    #print(i,a_list[i],a_list[i+1])
    
    #条件への一致を調べる
    if a_list[i] + a_list[i+1] > x:
        
        #右側のみ食べれば条件達成できる
        if x - a_list[i] <= a_list[i+1]:
            ans += a_list[i] + a_list[i+1] - x
            a_list[i+1] = x - a_list[i]
        #右側は完食。左も食べれば、条件達成できる。
        else:
            ans += a_list[i+1] + a[i] - x
            a[i] = x - a_list[i+1]
            a_list[i+1] = 0
            
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc048/tasks/arc064_a
# 問題文により、操作後の数列は以下を満たす
# x>=a[i]+a[i+1]
# よって、x-a[i] >= a[i+1]を満たすようにa[i+1]を決定していけば良い
# 実際に与えられたaと満たすように作ったaの差が答え


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

ans = 0
for i in range(N - 1):
    new = x - A[i]
    if new >= A[i + 1]:
        # 条件を満たしているのでok
        continue
    ans += A[i + 1] - new
    A[i + 1] = new

print(ans)

Submission status: Wrong Answer

Solution code:
# import numpy as np
# import math
import sys
input = sys.stdin.readline


def main():
    N,x = map(int,input().split())
    a = list(map(int,input().split()))

    res = 0

    if a[0] >= x:
        res += a[0] - x
        a[0] = x
        # print(res)
    # print(res)

    temp = a[0] + a[1] - x
    if temp >= 0:
        res += temp
        a[1] -= temp
    # print(res)

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

    # print(a)
    print(res)



main()

Submission status: Wrong Answer

Solution code:
# import numpy as np
# import math
import sys
input = sys.stdin.readline


def main():
    N,x = map(int,input().split())
    a = list(map(int,input().split()))

    res = 0

    for i in range(1,N):
        temp = a[i-1] + a[i] - x
        a[i] -= max(temp,0)
        res += max(temp,0)

    print(res)



main()

Submission status: Wrong Answer

Solution code:
# import numpy as np
# import math
import sys
input = sys.stdin.readline


def main():
    N,x = map(int,input().split())
    a = list(map(int,input().split()))

    res = 0

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

    print(res)



main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def main():
    N,x = map(int,input().split())
    a = list(map(int,input().split()))
    
    ans = 0
    for i in range(N-1):
        if (a[i+1] + a[i] > x):
            eat = a[i+1]+a[i]-x
            ans += eat
            a[i+1] -= eat
            
    print(ans)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

for i in range(1,N):
  if A[i-1]+A[i]>x:
    ans +=A[i-1]+A[i]-x
    A[i] -=A[i-1]+A[i]-x
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if alist[0] > x:
    alist[0] -= (alist[0] - x)

for al in range(1,N):
    if (alist[al-1]+alist[al]) > x:
        ans += (alist[al-1]+alist[al]) - x
        alist[al] -= (alist[al-1]+alist[al]) - x

print(ans)

Submission status: Wrong Answer

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

if alist[0] > x:
    alist[0] -= (alist[0] - x)

for al in range(1,N):
    while (alist[al-1]+alist[al]) > x:
        alist[al] -= 1
        ans += 1

print(ans)

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):
    sum = a[i] + a[i+1]
    if sum > x:
        a[i+1] -= (sum - x)
        ans += (sum - x)

print(ans)

Submission status: Wrong Answer

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

ans = 0
while a[0] > x:
  a[0] -= 1
  ans += 1
while a[-1] > x:
  a[-1] -= 1
  ans += 1

for i in range(1,len(a)-1):
  if a[i] == 0:
    break
  while a[i-1]+a[i] > x or a[i]+a[i+1] > x:
    a[i] -= 1
    ans += 1
    if a[i] == 0:
      break

print(ans)

Submission status: Wrong Answer

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

s=0
if(A[0]>N):
    s+=A[0]-N
    A[0]=N

for i in range(N-1):
    if(A[i+1]>N):
        s+=A[i+1]-N
        A[i+1]=N
    if(A[i]+A[i+1]>N):
        t=A[i]+A[i+1]-N
        s+=t
        A[i+1]-=t

print(s)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
ans = 0 ;count = 0 ;pro = 1

n,x=map(int,input().split())
A=list(map(int,input().split()))
for i in range(n-1):
    if A[i]+A[i+1]>x:
        count+=A[i+1]-(x-A[i])
        A[i+1]=x-A[i]
        # print(x-A[i],i)
print(count)

Submission status: Wrong Answer

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

cnt = 0
for i in range(2, N+1):
    if a[i-1]+a[i]>x:
        cnt += a[i]+a[i-1]-x
        a[i] -= a[i]+a[i-1]-x
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
import copy
if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N, M = MAP()
L = MAP()

ans = []
for n in range(2):
	tmp = 0
	A = copy.deepcopy(L)
	for i in range(N-1):
		if A[i]+A[i+1] > M:
			t = i if n % 2 else i+1
			tmp += (A[i]+A[i+1] - M)
			A[t] -= (A[i]+A[i+1] - M)
	ans.append(tmp)
print(min(ans))

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
a = list(map(int, input().split()))
adja_candi = []
for i in range(n-1):
    adja_candi.append(a[i] + a[i+1])
adja_candi += [0]
ans = 0
if x == 0:
    print(sum(a))
    exit()
for i in range(len(adja_candi)-1):
    if adja_candi[i] > x:
        count = adja_candi[i] - x
        adja_candi[i] -= count
        adja_candi[i+1] -= count
        ans += count
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

    # while a[i-1] + a[i] > x:
    #     a[i] -= 1
    #     ans += 1

print(ans)

Submission status: Wrong Answer

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

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

# 食べる数
tabeta = 0

# xを超えている数を出す
for n in range(N):
    if a[n] > x:
        # 超えている分は食べる
        tabeta += a[n] - x
        # 食べたので、残りはt個
        a[n] = x
        
# 隣り合っている数がXを超えているかチェック
for n in range(N-1):
    # 隣り合う数を足してもxを超える分は食べる
    if a[n] + a[n+1] > x:
        ima_taberu = a[n] + a[n+1] -x
        
        # いっぱいある方を食べる
        if a[n] > a[n+1]:
            a[n] -= ima_taberu
        elif a[n] < a[n+1]:
            a[n+1] -= ima_taberu
        elif a[n] == a[n+1]:
            a[n+1] -= ima_taberu
        tabeta += ima_taberu

print(tabeta)

Submission status: Wrong Answer

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

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

# 食べる数
tabeta = 0

# xを超えている数を出す
for n in range(N):
    if a[n] > x:
        # 超えている分は食べる
        tabeta += a[n] - x
        # 食べたので、残りはt個
        a[n] = x
        
# 隣り合っている数がXを超えているかチェック
for n in range(N-1):
    print(a)
    # 隣り合う数を足してもxを超える分は食べる
    if a[n] + a[n+1] > x:
        ima_taberu = a[n] + a[n+1] -x
        
        # いっぱいある方を食べる
        if a[n] > a[n+1]:
            a[n] -= ima_taberu
        elif a[n] < a[n+1]:
            a[n+1] -= ima_taberu
        elif a[n] == a[n+1]:
            a[n+1] -= ima_taberu
        tabeta += ima_taberu

print(tabeta)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
for i in range(n-1):
    s = a[i] + a[i+1]
    if i % 2 == 0:
        if s > x:
            minus = s - x
            if a[i+1] >= minus:
                a[i+1] -= minus
                cnt += minus
            else:
                a[i+1] = 0
                a[i] -= minus - a[i+1]
                cnt += minus
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,x = MI()
    A=LI()
    ans = 0
   
    for i in range(N-1):
      if A[i]+A[i+1]>x:
        s=A[i]+A[i+1]
        A[i+1]-=min(A[i+1],x-s)
        ans += max(0,s-x)

    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,x = MI()
    A=LI()
    ans = 0
   
    for i in range(N-1):
      if A[i]+A[i+1]>x:
        s=A[i]+A[i+1]
        A[i+1]-=max(A[i+1],x-s)
        ans += max(0,s-x)

    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,x = MI()
    A=LI()
    ans = 0
    S=[]
    for i in range(N-1):
        S.append(A[i]+A[i+1])
    for i,_ in enumerate(S[:-1]):
        ans += max(0,S[i]-x)
        S[i+1]-=max(0,S[i]-x)
        S[i]-=max(0,S[i]-x)

    ans += max(0,S[-1]-x)
    print(ans)
        
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,x = MI()
    A=LI()
    ans = sum([max(0,a-x) for a in A])
    A=[min(a,x) for a in A]
    for i in range(1,N,2):
        large = A[i-1]
        if i!=N-1:
            large = max(large, A[i+1])
        can = x-large
        ans += max(0,A[i]-can)
    print(ans)
        
    
if __name__ == '__main__':
    main()

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:
    temp=a[i]+a[i+1]-x
    ans+=temp
    if a[i+1]>=temp:
      a[i+1]-=temp
    else:
      a[i+1]==0
print(ans)

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:
    temp=a[i]+a[i+1]-x
    ans+=temp
    a[i+1]-=temp
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(N):
    if wa[i] <= x:
        continue
    if wa[i] > x:
        ans += wa[i]-x
        a[i] -= wa[i]-x
        wa[i] -= wa[i]-x
        wa[i+1] -= wa[i+1]-x
        continue

if wa[-1] > x:
    ans += wa[-1]-x
    wa[-1] -= wa[-1]-x

print(ans)

Submission status: Wrong Answer

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

for i in range(N):
    if wa[i] <= x:
        continue
    if wa[i] > x:
        ans += wa[i]-x
        a[i] -= wa[i]-x
        wa[i] -= wa[i]-x
        wa[i+1] -= wa[i+1]-x
        continue

print(ans)

Submission status: Wrong Answer

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

for i in range(N):
    print(i, a,wa,ans)
    if wa[i] <= x:
        continue
    if wa[i] > x:
        ans += wa[i]-x
        a[i] -= wa[i]-x
        wa[i] -= wa[i]-x
        wa[i+1] -= wa[i+1]-x
        continue

print(ans)

Submission status: Wrong Answer

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

for i in range(N):
    if wa[i] <= x:
        continue
    if a[i] >= x:
        ans += wa[i]-x
        a[i] -= wa[i]-x
        wa[i] -= wa[i]-x
        wa[i+1] -= wa[i+1]-x
        continue
    if a[i] < x:
        ans += wa[i]-x
        a[i] = 0
        a[i] = x
        wa[i] = x

print(ans)

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):
  eated=max(0,A[i]+A[i-1]-x)
  ans+=eated
  A[i]-=eated
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, X, A):
    ans = 0
    for i, a in enumerate(A):
        ans += max(0, a-X)
        A[i] = min(a, X)
    for i in range(1, N-1):
        if A[i-1] + A[i] > X:
            ans -= X - (max(A[i-1], A[i+1]) + A[i])
            A[i] += X - (max(A[i-1], A[i+1]) + A[i])
    if A[-1] + A[-2] > X:
        ans -= X - (A[-1] + A[-2])
        A[i] += X - (A[-1] + A[-2])
    return ans


def main():
    N, X = read_int_n()
    A = read_int_n()
    print(slv(N, X, A))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,x = map(int, input().split())
a = list(map(int, input().split()))
now = min(a[0],x)
ans = max(0,a[0]-x)
for i in a[1:]:
  SUM = now + i
  res = SUM - x
  if res > 0:
    ans += res
    now = i - res
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

C=A[:]

s2=0
for i in range(n-1):


    v=C[n-1-i]+C[n-2-i]
    if v>x:
        s2+=v-x
        C[n-2-i]=0 if v<=C[n-1-i] else x-C[n-1-i]
print(s2)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
A=list(map(int,input().split()))
B=A[:]
C=A[:]
s1=0
s2=0
for i in range(n-1):
    w=B[i]+B[i+1]
    if w>x:
        s1+=w-x
        B[i+1]=0 if x<=B[i] else x-B[i]
    v=C[n-1-i]+C[n-2-i]
    if v>x:
        s2+=v-x
        C[n-2-i]=0 if v<=C[n-1-i] else x-C[n-1-i]
print(min(s1,s2))

Submission status: Wrong Answer

Solution code:
def examC():
    N, x = LI()
    a = LI()
    cur = int(0)
    for i in range(N-1):
        cur += max((a[i]+a[i+1])-x,0)
        a[i+1] = min(x-a[i],a[i+1])
    print(cur)


import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

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):
    s=a[i]+a[i+1]
    if s>x:
        if s-x<=a[i+1]:
            a[i+1]-=s-x
        ans+=s-x
print(ans)

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
for i in range (1, len(a)):
	if a[i-1] + a[i] < x:
		continue
	else:
		sa = a[i-1] + a[i] -x
		a[i] -= sa
		cnt += sa
print (cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.append(0)
count = 0
for i in range(1, n+1, 2):
        t = a[i-1] + a[i]
        if t <= x:
                break;
        else:
                count += t - x
print(count)

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
a = list(map(int, input().split()))
count = 0
for i in range(1, n, 2):
        t = a[i-1] + a[i]
        if t <= x:
                break;
        else:
                count += t - x
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

c=0

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

Submission status: Wrong Answer

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

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

c=0

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

Submission status: Wrong Answer

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

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

c=0

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