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 = list(map(int,input().split()))
a=list(map(int,input().split()))

eat=0

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

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

Submission status: Wrong Answer

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

eat=0

if a[0]>x:
  eat+=a[0]-x+1
  a[0]=x-1

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

Submission status: Wrong Answer

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

eat=0

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

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
    a[0]-=a[0]-x
if a[-1]>x:
    ans+=a[-1]-x
    a[-1]-=a[-1]-x
for i in range(n-2):
    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:
#!/usr/bin/env python3
import sys


def solve(N: int, x: int, a: "List[int]"):
    answer =0
    for i in range(N-1):
        consum = a[i]+a[i+1]
        if consum > x:
            a[i+1]-= consum-x
            answer+=consum-x
        
    print(answer)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, x, a)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n, x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
# count = 0
# for i in a:
#     if i > x:
#         i = x
#         count += i - x
b = a.copy()

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

count2 = 0
for i in range(n-1):
    if b[i] + b[i+1] > x:
        d = b[i] + b[i+1] - x
        if b[i+1] >= d:
            b[i+1] -= d
        else:
            b[i+1] = 0
            b[i] -= d - b[i]
        count2 += d

count = min(count1, count2)
print(count)

Submission status: Wrong Answer

Solution code:
n, x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
count = 0
for i in a:
    if i > x:
        i = x
        count += i - x
b = a.copy()

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

count2 = count
for i in range(n-1):
    if b[i] + b[i+1] > x:
        d = b[i] + b[i+1] - x
        if b[i+1] >= d:
            b[i+1] -= d
        else:
            b[i+1] = 0
            b[i] -= d - b[i]
        count2 += d

count = min(count1, count2)
print(count)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs= sys.stdin.buffer.readlines
#rstrip().decode('utf-8')

#import numpy as np
#import operator
#import bisect
#from heapq import heapify,heappop,heappush
#from math import gcd
#from fractions import gcd
#from collections import deque
#from collections import defaultdict
#from collections import Counter
#from itertools import accumulate
#from itertools import groupby
#from itertools import permutations
#from itertools import combinations
#scipy.sparse import csr_matrix
#scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse.csgraph import csgraph_from_dense
#from scipy.sparse.csgraph import dijkstra
#sys.setrecursionlimit(10**7)

#map(int,input().split())

def main():
    N,x,*a=map(int,read().split())
    t=0
    ans=0
    for i in range(N-1):
        now=a[i]-t
        t=max(0,now+a[i+1]-x)
        ans+=t
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
l=[int(i) for i in input().split()]
sm=0 
for i in range(n-1):
    if l[i]+l[i+1]<=k:
        continue 
    else: 
        sm+=l[i]+l[i+1]-k 
        req=l[i]+l[i+1]-k 
        if l[i+1]>=sm: 
            l[i+1]-=sm 
            req=0 
        else: 
            #l[i+1]=0 
            req-=l[i+1]
            l[i]-=req
            l[i+1]=0
#print(l)
print(sm)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
l=[int(i) for i in input().split()]
sm=0 
for i in range(n-1):
    if l[i]+l[i+1]<=k:
        continue 
    else: 
        sm+=l[i]+l[i+1]-k 
        req=sm 
        if l[i+1]>=sm: 
            l[i+1]-=sm 
            req=0 
        else: 
            #l[i+1]=0 
            req-=l[i+1]
            l[i]-=req
            l[i+1]=0
#print(l)
print(sm)

Submission status: Wrong Answer

Solution code:
#ABC048 C - Boxes and Candies
N,x = map(int,input().split())
A = list(map(int,input().split()))
A_ = 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

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

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+=a[0]-x
for i in range(len(a)-1):
    if a[i]+a[i+1]>x:  
        b=a[i+1]-x+a[i]
        a[i+1]=x-a[i]
        ans+=b
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(len(a)-1):
    if a[i]+a[i+1]>x:  
        b=a[i+1]-x+a[i]
        a[i+1]=x-a[i]
        ans+=b
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(len(a)-1):
    if a[i]+a[i+1]>x:  
        b=a[i+1]-x+a[i]
        a[i+1]=x-a[i]
        ans+=b
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(len(a)-1):
    if a[i]+a[i+1]>=x:  
        b=a[i+1]-x+a[i]
        a[i+1]=x-a[i]
        ans+=b
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,x = map(int,input().split())
a = list(map(int,input().split()))
i = 0
answer = 0
while i < N-1:
    if a[i] + a[i+1] > x:
        answer = answer + x - a[i] - a[i+1]
        a[i+1] = x - a[i]
        i = i+1
print(answer)

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):
    if a[i] >= x:
        ans += a[i]-x
        a[i] = x
for j in range(n-1):
    if a[j] + a[j+1] >= x:
        ans += a[j+1] - (x - a[j])
        a[j+1] = x - a[j] - a[j+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):
    if a[i] >= x:
        ans += a[i]-x
        a[i] = x
for j in range(n-1):
    if a[j] + a[j+1] > x:
        ans += a[j+1] - (x - a[j])
        a[j+1] = x - a[j] - a[j+1]
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
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 and a[i + 1] >= 1: # 左の組から順に、組の右側から食べていく
        ans += min(a[i] + a[i + 1] - x, a[i + 1])
        a[i + 1] -= min(x, a[i + 1])
    if a[i] + a[i + 1] > x: # それでも足りないなら組の左側も食べる
        ans += a[i] + a[i + 1] - x
        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(n-1):
    if a[i] + a[i+1] > x:
        ans += a[i+1] - (x - a[i])
        a[i+1] = x - a[i] - a[i+1]
print(ans)

Submission status: Wrong Answer

Solution code:
n, x = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
dio = 0 #お前は今までに食べたキャンディの数を覚えているのか？
for i in range(n - 1):
    extra = a[i] + a[i + 1] - x
    if(extra > 0):
        a[i + 1] -= extra
        dio += extra
print(dio)

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:
        ans += a[i+1] - (x - a[i])
        a[i+1] = x - a[i]
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:
    ans += a[i-1]+a[i]-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()))
count = 0
for i in range(n - 1):
    if a[i] + a[i + 1] > x:
        count += a[i] + a[i + 1] - x
        if a[i + 1] >= x:
            a[i + 1] = x - a[i]
        else:
            a[i + 1] = 0
            a[i] = x
print(int(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(n - 2):
    if a[i] + a[i + 1] > x:
        count += a[i] + a[i + 1] - x
        a[i + 1] = x - a[i]
if a[n - 2] + a[n - 1] > x:
    count += a[n - 2] + a[n - 1] - x
print(int(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(n - 1):
    if a[i] + a[i + 1] > x:
        count += a[i] + a[i + 1] - x
        a[i + 1] = x - a[i]
print(int(count))

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
def main():
    N, x = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    S = [max(A[i] + A[i+1] - x,0) for i in range(N-1)]
    must_reduce = [0] * (N-2)
    if N == 2:
        return print(S[0])
    for i in range(N-1):
        if i == 0:
            must_reduce[i] = S[i]
            S[i] = 0
            S[i+1] = max(S[i+1] - must_reduce[i],0)
            continue
        if i == N-2:
            must_reduce[N-3] += S[i]
            S[i] = 0
            continue
        must_reduce[i] = S[i]
        S[i] = 0
        S[i+1] = max(S[i+1] - must_reduce[i],0)
    print(sum(must_reduce))

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

Submission status: Wrong Answer

Solution code:
N,X = map(int,input().split())
A = list(map(int,input().split()))
ans = 0
if X == 0:
  print(sum(A))
else:
  for i in range(N-1):
    if A[i] + A[i+1] >=X:
      if A[i] > A[i+1]:
        ans += (A[i] + A[i+1] - X)
        A[i] -= (A[i] + A[i+1] - X)
      else:
        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] * N

for i in range(1, N):
    calc = max(0, a[i-1] + a[i] - x)
    if calc < a[i-1]:
        a[i-1] = calc
        ans[i-1] = calc
    else:
        a[i] -= calc
        ans[i] = calc

print(sum(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):
    num_eat_candy = max(0, (a[i - 1] + a[i]) - x)
    ans += num_eat_candy
    a[i] = min(0, a[i] - num_eat_candy)
    # a[i] -= num_eat_candy
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):
    num_eat_candy = max(0, (a[i - 1] + a[i]) - x)
    ans += num_eat_candy
    a[i] -= num_eat_candy
print(ans)

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split(" "))
list_a = list(map(int, input().split(" ")))
count = 0
last = 0
for a in list_a:
  act = max(0, last + a - x)
  last = x - last
  count += act
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    N,x = map(int, sys.stdin.readline().split())
    a = list(map(int, sys.stdin.readline().split()))
    ans=0
    for i in range(N-1):
        eated = max(0,a[i]+a[i+1]-x)
        ans += eated
        a[i+1]-=eated
    print(ans)

Submission status: Wrong Answer

Solution code:
N,x,*A=map(int,open(0).read().split())
L=[a+b for a,b in zip(A,A[1:])];s=sum(L)
for i in range(N-2):L[i+1]-=max(0,L[i]-x)
L[-1]=min(L[-1],x)
print(s-sum(L))

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 = x-a[0]
    a[0]=x
for i in range(n-1):
    b = a[i]+a[i+1]
    if b<=x:
        continue
    else:
        sub = b-x
        a[i+1] = a[i+1]-sub
        ans+=sub
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):
    b = a[i]+a[i+1]
    if b<=x:
        continue
    else:
        sub = b-x
        a[i+1] = a[i+1]-sub
        ans+=sub
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

tmp = A[0] + A[1]
red = max(0,tmp - x)
ans = red
if red > 0:
    if red <= A[1]:
        A[1] -= red
    else:
        A[0] -= red - A[1]
tmp = A[0] + A[1]


for i in range(2,N):
    tmp += A[i]
    tmp -= A[i-2]
    
    red = max(0,tmp - x)
    ans += red
    if red > 0:
        if red <= A[i]:
            A[i] -= red
        else:
            A[i-1] -= red - A[i]
    tmp = A[i-1] + A[i]   
print(ans)

Submission status: Wrong Answer

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

tmp = A[0] + A[1]
ans = max(0,tmp-x)
tmp = min(tmp,x)
for i in range(2,N):
    tmp += A[i]
    tmp -= A[i-2]
    ans += max(0,tmp-x)
    tmp = min(tmp,x)
    
print(ans)

Submission status: Wrong Answer

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

ans = 0
for i in range(N-1):
  sur = max(A[i] + A[i+1] - x, 0)
  ans += sur
  A[i+1] -= sur
  
anss = 0
for i in range(N-1):
  sur = max(B[N-i-1] + B[N-i-2] - x, 0)
  anss += sur
  B[N-i-2] -= sur
  
print(min(ans, anss))

Submission status: Wrong Answer

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

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

count = 0

# いきなりオーバー
if A[0] > x:
    diff = (A[0])-x
    count += diff
    A[0] = 1

for i in range(1, N):
    # 超えてたら、ギリまで下げる
    if A[i]+A[i-1] > x:
        diff = (A[i]+A[i-1])-x
        A[i] -= diff
        count += diff

print(count)

Submission status: Wrong Answer

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

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

count = 0
for i in range(1, N):
    # 超えてたら、ギリまで下げる
    if A[i]+A[i-1] > x:
        diff = (A[i]+A[i-1])-x
        A[i] -= diff
        count += diff

print(count)

Submission status: Wrong Answer

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

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(n-1)]
b1 = list(map(lambda h:max(0,h-x), b))
b2 = b1.copy()

ans1 = 0
for i in range(n-2):
    tmp = min(b1[i], b1[i+1])
    b1[i] -= tmp
    b1[i+1] -= tmp
    ans1 += tmp
ans1 += sum(b1)

ans2 = 0
for i in range(n-2):
    tmp = min(b2[i], b2[i+1])
    b2[i] -= tmp
    b2[i+1] -= tmp
    ans2 += tmp
ans2 += sum(b2)

print(min(ans1, ans2))

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(n-1)]
b = list(map(lambda h:max(0,h-x), b))
ans = 0
for i in range(n-2):
    tmp = min(b[i], b[i+1])
    b[i] -= tmp
    b[i+1] -= tmp
    ans += tmp
print(ans+sum(b))

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(n-1)]
b = list(map(lambda h:h-x, b))
ans = 0
for i in range(n-2):
    tmp = min(b[i], b[i+1])
    b[i] -= tmp
    b[i+1] -= tmp
    ans += tmp
print(max(0, ans+sum(b)))

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(n-1)]
b = list(map(lambda h:h-x, b))

ans = 0
for i in range(n-2):
    tmp = min(b[i], b[i+1])
    b[i] -= tmp
    b[i+1] -= tmp
    ans += tmp
print(max(0, ans+sum(b)))

Submission status: Wrong Answer

Solution code:
import math
N, x = map(int, input().split())
A = [int(_) for _ in input().split()]

diff = [a - x if a - x > 0 else 0 for a in A]
count = sum(diff)

real_A = [x if a > x else a for a in A]

for n in range(1, N):
    if A[n - 1] + A[n] > x:
        if A[n - 1] == x:
            count += A[n]
            A[n] = 0
        else:
            count += x - A[n - 1]
            A[n] = x - A[n - 1]
print(count)

Submission status: Wrong Answer

Solution code:
import math
N, x = map(int, input().split())
A = [int(_) for _ in input().split()]

diff = [a - x if a - x > 0 else 0 for a in A]
count = sum(diff)

real_A = [x if a > x else a for a in A]

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

Submission status: Wrong Answer

Solution code:
import math
N, x = map(int, input().split())
A = [int(_) for _ in input().split()]

count = 0
for n in range(1, N):
    if A[n - 1] + A[n] > x:
        count += A[n - 1] - math.ceil(x/2)
        count += A[n] - math.floor(x/2)
        A[n - 1] = math.ceil(x/2)
        A[n] = math.floor(x/2)
print(count)

Submission status: Wrong Answer

Solution code:
a,b = map(int,input().split())
li = list(map(int,input().split()))

cnt = 0
if li[0]>b:
    li[0] = b
    cnt += li[0]-b
for i in range(a-1):
    if li[i]+li[i+1] > b:
        cnt += (li[i]+li[i+1] - b)
        li[i+1] -= (li[i]+li[i+1] - b)
        
print(cnt)

Submission status: Wrong Answer

Solution code:
a,b = map(int,input().split())
li = list(map(int,input().split()))

cnt = 0
for i in range(a-1):
    if li[i]+li[i+1] > b:
        cnt += (li[i]+li[i+1] - b)
        li[i+1] -= min(cnt,li[i+1])
        
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,x=map(int,input().split())
    A=list(map(int,input().split()))
    res=0
    for i in range(1,n):
        c=A[i]+A[i-1]-x
        if c>0:
            res+=c
            A[i]-=c
    print(res)
resolve()

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):
  if a[i] >= x:
    cnt += a[i]-x
    a[i]=x
    
for j in range(n-1):
  if a[j]+a[j+1]>=x:
    cnt += a[j]+a[j+1]-x    
    a[j+1] = a[j]+a[j+1]-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):
  if a[i]+a[i+1] > x:
    dif = a[i]+a[i+1]-x
    a[i+1] -= dif
    cnt += dif
print(cnt)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

m = min(a)
ans = 0
for i in range(N):
    if i % 2 == 1 and i != N - 1:
        if a[i] + max(a[i-1], a[i + 1]) > x:
            k = max(a[i - 1], a[i + 1])
            tmp = max((x - k), 0)

            tmp = min(tmp, a[i])
            ans += a[i] - tmp
            a[i] = tmp

    elif i % 2 == 1 and i == N - 1:
        if a[i] + a[i-1] > x:
            tmp = max(x - a[i-1], 0)

            tmp = min(tmp, a[i])
            ans += a[i] - tmp
            a[i] = tmp

    else:
        if i != 0:
            if a[i-1] + a[i] > x:
                tmp = min(x - a[i-1], a[i])
                ans += a[i] - tmp
                a[i] = tmp

if a[0] + a[1] > x:
    tmp = min(x - a[1], a[0])
    ans += a[0] - tmp
    a[0] = tmp

print(ans)

Submission status: Wrong Answer

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

m = min(a)
ans = 0
for i in range(N):
    if i % 2 == 1 and i != N - 1:
        k = max(a[i - 1], a[i + 1])
        tmp = max((x - k), 0)
        tmp = min(tmp, a[i])
        ans += a[i] - tmp
        a[i] = tmp
    elif i % 2 == 1 and i == N - 1:
        tmp = max(x - a[i-1], 0)
        tmp = min(tmp, a[i])
        ans += a[i] - tmp
        a[i] = tmp
    else:
        if i != 0:
            if a[i-1] + a[i] > x:
                tmp = min(x - a[i-1], a[i])
                ans += a[i] - tmp
                a[i] = tmp

if a[0] + a[1] > x:
    tmp = min(x - a[1], a[0])
    ans += a[0] - tmp
    a[0] = tmp

print(ans)

Submission status: Wrong Answer

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

m = min(a)
ans = 0
for i in range(N):
    if i % 2 == 1 and i != N - 1:
        k = max(a[i - 1], a[i + 1])
        tmp = max((x - k), 0)
        tmp = min(tmp, a[i])
        ans += a[i] - tmp
        a[i] = tmp
    elif i % 2 == 1 and i == N - 1:
        tmp = max(x - a[i-1], 0)
        ans += a[i] - tmp
        a[i] = tmp
    else:
        if i != 0:
            if a[i-1] + a[i] > x:
                tmp = min(x - a[i-1], a[i])
                ans += a[i] - tmp
                a[i] = tmp

if a[0] + a[1] > x:
    tmp = min(x - a[1], a[0])
    ans += a[0] - tmp
    a[0] = tmp

print(ans)

Submission status: Wrong Answer

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

m = min(a)
ans = 0
for i in range(N):
    if i % 2 == 1 and i != N - 1:
        k = max(a[i - 1], a[i + 1])
        tmp = max((x - k), 0)
        tmp = min(tmp, a[i])
        ans += a[i] - tmp
        a[i] = tmp
    elif i % 2 == 1 and i == N - 1:
        tmp = max(x - a[i-1], 0)
        ans += a[i] - tmp
        a[i] = tmp
    else:
        if i != 0:
            if a[i-1] + a[i] > x:
                ans += a[i] - (x - a[i-1])
                a[i] = x - a[i-1]

if a[0] + a[1] > x:
    ans += a[0] - (x - a[1])
    a[0] = (x - a[1])


print(ans)

Submission status: Wrong Answer

Solution code:
a,b = map(int,input().split())
li = list(map(int,input().split()))

cnt = 0
for i in range(a-1):
    if li[i]+li[i+1] > b:
        cnt += (li[i]+li[i+1] - b)
        li[i+1] -= max(cnt,li[i+1])
print(cnt)

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

        else:
            A[i+1] = 0

print(ans)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

Solution code:
N,x= map(int,input().split())
array = list(map(int,input().split()))
array2=array.copy()
result=0
#TLE pattern
# for i in range(0,N-1):
#     #i と i+1 が閾値以下じゃなかったら 
#     while array[i] + array[i+1] > x:
#         if array[i+1]!=0:
#             array[i+1]-=1
#         else:
#             array[i]-=1
#         result+=1
# print(result)

for i in range(0,N-1):
    if array[i] + array[i+1] > x:
        # if array[i+1] - (array[i] + array[i+1] - x) >= 0:
        #     array[i+1]=array[i+1] - (array[i] + array[i+1] - x)
        if (array[i]+array[i+1])-x <= array[i+1]:
            array[i+1]= array[i+1] - (array[i]+array[i+1]-x)
        else:
            # array[i]=array[i] - (array[i]+array[i+1]) - x - array[i+1]
            array[i]= array[i]-(array[i]-x)
            array[i+1]=0

print(array2)
print(array)
print(sum(array2)-sum(array))

Submission status: Wrong Answer

Solution code:
N,x= map(int,input().split())
array = list(map(int,input().split()))
array2=array.copy()
result=0
#TLE pattern
# for i in range(0,N-1):
#     #i と i+1 が閾値以下じゃなかったら 
#     while array[i] + array[i+1] > x:
#         if array[i+1]!=0:
#             array[i+1]-=1
#         else:
#             array[i]-=1
#         result+=1
# print(result)

for i in range(0,N-1):
    if array[i] + array[i+1] > x:
        if array[i+1] - (array[i] + array[i+1] - x) >= 0:
            array[i+1]=array[i+1] - (array[i] + array[i+1] - x)
        else:
            array[i] - (x-array[i+1])
            array[i+1]- x
# print(array2)
# print(array)
print(sum(array2)-sum(array))

Submission status: Wrong Answer

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

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