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: Runtime Error

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

Submission status: Runtime Error

Solution code:
// abc048_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    ll N, x;
    cin >> N >> x;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    ll ans = 0;
    ll tmp = A[0];
    REPN(i, 1, N){
        ll sm = tmp + A[i];

        ll diff = sm > x ? sm - x : 0;
        A[i] -= diff;
        ans += diff;
        
        if (A[i] < 0){
            A[i] = 0;
        }

        tmp = A[i];
    }

    print(ans);

    return 0;
}

Submission status: Runtime Error

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

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

print(res)

Submission status: Runtime Error

Solution code:
n,x,*a=map(int,open(0).read().split());r=0
for i in range(1,N):e=max(a[i]+a[i-1]-x,0);a[i]-=min(e,a[i]);r+=e
print(r)

Submission status: Runtime Error

Solution code:
X = [int(e) for e in input().split()]
A = [int(f) for f in input().split()]
i=0
ans=0
while i<X[0]:
    if(A[i] + A[i+1]) <= X[1] and i+1 < X[0]:
        i+=1
    else:
        A[i+1] -= 1
        ans += 1
        continue
    i+=1
print(ans)

Submission status: Runtime Error

Solution code:
A=list(map(int,input().split())) +[0]
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: Runtime Error

Solution code:
N, x = map(int, input().split())
a = list(map(int, inout().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: Runtime Error

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: Runtime Error

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

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

Submission status: Runtime Error

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)]

ans = max(0, a[0] - x)
b[0] -= ans

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

count = 0

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

    if i % 2 is not 0:
        if candies[i-1] + candies[i] > x:
            count += candies[i-1] + candies[i] - x
            candies[i] -= candies[i-1] + candies[i] - x

        if i is not n-1 and candies[i+1] + candies[i] > x:
            count += candies[i+1] + candies[i] - x
            candies[i] -= candies[i+1] + candies[i] - x

print(count)

Submission status: Runtime Error

Solution code:
a,b,x=map(int,input().split())
n=b-a+1
l=[0]*(n+1)
init=a
for i in range(1,n+1):
    if init%x==0:
        l[i]=l[i-1]+1
    else:
        l[i]=l[i-1]
    init+=1
    
print(l[-1]-l[0])

Submission status: Runtime Error

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:　#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: Runtime Error

Solution code:
import copy
[n,x]=list(map(int,input().split()))
a=list(map(int,input().split()))
a0=copy.copy(a)
ans=0
if a[0]+a[1]>x and a[0]>x:
	a[0]-=a[0]-x
	ans+=a0[0]-x
		if a[0]+a[1]>x:
			a[1]=0
			ans+=a[1]
	
for i in range(1,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: Runtime Error

Solution code:
import copy
[n,x]=list(map(int,input().split()))
a=list(map(int,input().split()))
a0=copy.copy(a)
ans=0
if a[0]+a[1]>x and a[0]>x:
	a[0]-=a[0]-x
	ans+=a[0]-x
		if a[0]+a[1]>x:
			a[1]=0
			ans+=a[1]
	
for i in range(1,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: Runtime Error

Solution code:
import copy
[n,x]=list(map(int,input().split()))
a=list(map(int,input().split()))
a0=copy.copy(a)
ans=0
if a[0]+a[1]>x and a[0]>x:
	a[0]-=a[0]-x
	and+=a[0]-x
		if a[0]+a[1]>x:
			a[1]=0
			ans+=a[1]
	
for i in range(1,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: Runtime Error

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 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: Runtime Error

Solution code:
n,m=map(int,input().split())
l=list(map(int,input().split()))
count=0
if l[i]>m:
  count+=-m+l[i]
  l[i]=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: Runtime Error

Solution code:
n,m=map(int,input().split())
l=list(map(int,input().split()))
count=0
if l[i]>m:
  count+=m-l[i]
  l[i]=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: Runtime Error

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

Submission status: Runtime Error

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

cnt=0
pre=0

for i in range(N):
  dif=max(A[i]+pre-x,0)
  cnt+=dif
  arr[i]-=dif
  pre=arr[i]
  
print(cnt)

Submission status: Runtime Error

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

Submission status: Runtime Error

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 - 1] + a[n] > x:
    count += a[n - 1] + a[n] - x
print(int(count))

Submission status: Runtime Error

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

answer = 0
if A[0] > X:
    answer += A[0] - X
    A[0] = X
    
for i in range(N-1):
    diff = A[i] + A[i+1] - X
    if diff > 0:
        answer += diff
        A[i+1] -= diff

print(answer)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N,x = map(int,input().split())
a = [int(i) for i in input.split()]
ans = 0
if a[0] > x:
  ans += (a[0]-x)
  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: Runtime Error

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

c = 0

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

print(c)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 31 14:24:15 2019

@author: priya
"""

inp = input().split()
n = int(inp[0])
x = int(inp[1])
candies = [int(x) for x in input().split()]

op = 0
for i in range(1,len(candies)):
    if candies[i-1] + candies[i] > x:
        eat = candies[i-1] + candies[i] - x
        if(eat > candies[i]):
            candies[i-1] -= eat - candies[i]
            candies[i] = 0
        else:    
            candies[i] -= eat
    op += eat
print(op)
#print(candies)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[30]:


"""
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."""


# In[63]:


rightDirective = 0
leftDirective = 1

def findSmallest(myList, index=1):
    newList = myList[:]
    newList.sort()
    smallestElement = newList[index-1]
    return myList.index(smallestElement)    

def anyElementGreater(myList, value):
    ret = False
    for i in myList:
        if i > value:
            ret = True
        else:
            continue
    return ret


# In[68]:


class CandyBoxes:
    N = 0
    x = 0
    candyList = []
    sumList = []
    toRemoveList = []
    def __init__(self, N, x, candyList):
        self.N = N
        self.x = x
        self.candyList = candyList
        self.sumList = []
        self.toRemoveList = []
        
        for i in range(len(self.candyList) - 1):
            mySum = candyList[i] + candyList[i+1]
            self.sumList.append( mySum )
            if mySum > x:
                self.toRemoveList.append( mySum - x )
            else:
                self.toRemoveList.append( 0 )            
        
    def reconfigureBoxes(self):
        for i in range(len(self.toRemoveList)):
            mySum = self.candyList[i] + self.candyList[i+1]
            if mySum > self.x:
                self.toRemoveList[i] = mySum - x
            else:
                self.toRemoveList[i] = 0
            self.sumList[i] = mySum
            
    def removeExtraCandies(self, direction):
        removed = 0
        i = 1
        
        while anyElementGreater(self.toRemoveList, x):
            currentIndex = findSmallest(self.toRemoveList, i)
            print(i, currentIndex, self.toRemoveList[currentIndex])
            i+=1
            
            if direction == leftDirective:
                if self.candyList[currentIndex] >= self.toRemoveList[currentIndex]:
                    self.candyList[currentIndex] -= x
                    self.reconfigureBoxes()
                    continue
                    
                elif self.candyList[currentIndex+1] >= self.toRemoveList[currentIndex]:
                    self.candyList[currentIndex+1] -= x
                    self.reconfigureBoxes()
                    continue
                    
                else:
                    print("Not implemented")
                    
        
                
            
        
    
        
        
        


# In[81]:


N, x = [int(i) for i in input().split()]
candyInBox = [int(i) for i in input().split()]


# In[82]:


myCandy = CandyBoxes(N, x, candyInBox)


# In[88]:


print(myCandy.candyList)
print(myCandy.sumList)
print(myCandy.toRemoveList)


# In[87]:


myCandy.removeExtraCandies(leftDirective)

Submission status: Runtime Error

Solution code:

def computeMinimumNoOfOperations(candies, x):
    noOfOperations = 0
    for i in range(len(candies) - 1):
        if (candies[i] > x):
          candiesTocandiesToEat = candies[i] - x
          candies[i] -= candiesTocandiesToEat
          noOfOperations += candiesToEat
        if (candies[i] + candies[i + 1] > x):
            candiesToEat = candies[i] + candies[i + 1] - x
            candies[i + 1] -= candiesToEat
            noOfOperations += candiesToEat 
    return noOfOperations


def start():
    n, x = list(map(int, input().split()))
    candies = list(map(int, input().split()))
    return computeMinimumNoOfOperations(candies, x)

print(start())

Submission status: Runtime Error

Solution code:


def computeMinimumNoOfOperations(candies, x):
  noOfOperations = 0
  for i in range(0, len(candies) - 1):
    if (candies[i] > x):
      eat = candies[i] - x
      candies[i] -= eat
      noOfOperations += eat
    if (candies[i] + candies[i + 1] > x):
      if (candies[i] > candies[i + 1]):
        eat = candies[i] - x
      	candies[i] -= eat
      	noOfOperations += eat 
      else:
        eat = candies[i + 1] - x
      	candies[i + 1] -= eat
      	noOfOperations += eat 
  return noOfOperations


def start():
  n, x = list(map(int, input().split()))
  candies = list(map(int, input().split()))
  return computeMinimumNoOfOperations(candies, x)

print(start())

Submission status: Runtime Error

Solution code:
s=input()
n=len(s)
if s[0]==s[-1] ^ n%2==0:
  print('Second')
else:
  print('First')

Submission status: Runtime Error

Solution code:
def minimumNumOfCandies(candies,atmostValue):
  candiesToEat = 0
  for i in range( 0 , len ( candies ) - 1 ) :
    if( candies[i] > atmostValue ) :
      candiesToEat = candiesToEat + ( candies[i] - atmostValue)
      candies[i] = candies[i] - ( candies[i] - atmostValue )
    if( candies[i] + candies[i + 1] > atmostValue ):
      candiesToEat = candiesToEat + ( candies[i + 1] - atmostValue )
      candies[i + 1] = candies[i + 1] - ( candies[i + 1] - atmostValue)
  return candiesToEat
n = list(int(i) for i in input())
candies = list( int (i) for i in input())
print(minimumNumOfCandies(candies,n[1]))

Submission status: Runtime Error

Solution code:
def minCandies(boxes,limit):
    out = 0
    for i in range(len(boxes) - 1):
        total = boxes[i] + boxes[i + 1]
        if total > limit:
            out += total - limit
            boxes[i + 1] = boxes[i + 1] - (total - limit)
            if boxes[i + 1] < 0:
                boxes[i + 1] = 0
    return out
    
num_of_boxes, limit = map(int,input().split())
boxes = list(map(int,input().split()))

if limit == 0:
    return sum(boxes)
elif max([a + b for (a,b) in zip(boxes[:-1],boxes[1:])) <= limit:
    return 0
else:
    return minCandies(boxes,limit)

Submission status: Runtime Error

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

cnt = 0

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

print(cnt)

Submission status: Runtime Error

Solution code:
# -*- coding:utf-8 -*-
"""考え方
   i:    0 1   2 3   4
------------------  
A[i]:  100 2 100 2 100

iが奇数のときのA[i]をまず減らす戦略が有効。

その後、まだ条件を満たさないなら、iが偶数のときのA[i]を減らす。

"""
def solve():
    N, x = list(map(int, input().split()))
    A = list(map(int, input().split()))

    ans = 0
    for i in range(1, N, 2):

        # iが奇数のときの数字を減らす。
        if A[i-1]+A[i] > x:
            diff = (A[i-1]+A[i]) - x
            if A[i] <= diff:
                A[i] -= diff
                ans += diff
    
    for i in range(0, N, 2):
        if i == N-1:
            if A[i]+A[i-1] > x:
                diff = (A[i]+A[i-1]) - x
                A[i] -= diff
                ans += diff

        # iが偶数のときの数字を減らす
        if A[i]+A[i+1] > x:
            diff = (A[i]+A[i+1]) - x
            A[i] -= diff
            ans += diff
    
    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:


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

count_candy_eat = 0

if(candy_list[-1] == 0):
    for i in (reversed(N)):
        if (i == N):
            continue
        else:
            if (candy_list[i] + candy_list[i-1] > x):
                count_candy_eat += candy_list[i] + candy_list[i-1] - x
                candy_list[i-1] = x - candy_list[i]

print(candy_list)

for i in range(N):
    if(i == 0):
        continue
    else:
        if(candy_list[i-1] + candy_list[i] > x):
            count_candy_eat += candy_list[i-1] + candy_list[i] - x
            candy_list[i] = x - candy_list[i-1]

print(count_candy_eat)

Submission status: Runtime Error

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

a2 = []
a3 = []
for i in range(n):
    if i % 2 == 0:
        a2.append(mina)
        a3.append(b)
    else:
        a2.append(b)
        a3.append(mina)

cnt2 = 0
cnt3 = 0
for i in range(n):
    if a[i] >= a2[i]:
        cnt2 += a[i] - a2[i]
    else:
        cnt2 = None
        break
    
for i in range(n):
    if a[i] >= a3[i]:
        cnt3 += a[i] - a3[i]
    else:
        cnt3 = None
        break

if cnt2 and cnt3:
    print(min(cnt2,cnt3))
elif cnta2:
    print(cnt2)
elif cnta3:
    print(cnt3)
else:
    print(0)

Submission status: Runtime Error

Solution code:
n,x=map(int,input().split())
l=list(map(int,input().split()))
c=0
if x==9:
  exit()
for i in range(n-1):
  a=l[i]
  b=l[i+1]
  if a+b>x:
    c+=a+b-x
    if b>=a-x and a>=x:
      l[i+1]-=a+b-x
      print('処理A')
    else:
      l[i+1]=0
      l[i]-=x-b
      print('処理B')
    print(l)
print(l)
print(c)

Submission status: Runtime Error

Solution code:
f,g = list(map(int,input().split()))

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

c = 1
p = 0
if a[0] > g:
    c += a[0] - g
    a[0] = g
while p <= f-1:
    if a[p-1] + a[p] > x:
        eat = a[p-1] + a[p] - x
        c += eat
        a[p] -= eat
    p += 1
print(c)

Submission status: Runtime Error

Solution code:
f,g = list(map(int,input().split()))

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

c = 1
p = 0
if a[0] > g:
    c += a[0] - g
    a[0] = g
while p <= f-1:
    if a[p-1] + a[p] > x:
        eat = a[p-1] + a[p] - x:
        c += eat
        a[p] -= eat
    p += 1
print(c)

Submission status: Runtime Error

Solution code:
f,g = list(map(int,input().split()))

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

c = 0
p = 0
if a[0] > g:
    c += a[0] - g
    a[0] = g
while p <= f-1:
    if a[p-1] + a[p] > x:
        eat = a[p-1] + a[p] - x:
        c += eat
        a[p] -= eat
    p += 1
print(c)

Submission status: Runtime Error

Solution code:
f,g = list(map(int,input().split()))

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

c = 0
p = 0
if a[0] > g:
    c += a[0] - g
    a[0] = g
while p <= f-1:
    if a[p-1] + a[p] > x:
        eat = a[p-1] + a[p] - x:
        c += eat
        a[p] -= e
    p += 1
print(c)

Submission status: Runtime Error

Solution code:
from sys import stdin

N, x = [int(x) for x in stdin.readline().rstrip().split()]
candys = [int(x) for x in stdin.readline().rstrip().split()]

count = 0

# xより多く入っている箱のキャンディは必ず食べる必要がある。
for i in range(N):
    if candys[i] > x:
        num = candys[i] - x
        candys[i] = x
        count += num
        print(candys)

print('count = ', count)
print('---------------------------')

# 隣り合った箱を見て、xを越えていれば食べる
for i in range(N-1):
    if candys[i] + candys[i+1] > x:
        num = candys[i] + candys[i+1] - x
        count += num
        candys[i+1] = candys[i+1] - num
        print(candys)
# 結果
print(count)

Submission status: Runtime Error

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

b = [0]
for i in range(n):
    b.append(a[i])
b.append(0)    
count = 0

if b[1] > x:
    counter = b[1] - x
    b[1] = x
for i in range(n+1):
    if b[i] + b[i+1] > x:
        s = b[i] + b[i+1] - x
        if b[i] - s > -1:
            b[i] = b[i] -s
            counter = counter + s
        else:
            k = b[i]
            counter = counter + s
            b[i] = 0
            b[i+1] = x
        
print(counter)

Submission status: Runtime Error

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

s = a[0] + a[1]
s.append(0)
p = 0
if a[0] > x:
    a[0] = x
    p = a[0] - x
    
for i in range(0,n):
    pp = a[i] + a[i + 1]
    if pp > x:
        a[i+1] = a[i+1] - pp + x
        p = p + pp -x
        
print(p)

Submission status: Runtime Error

Solution code:
N,x=map(int,input().split())
S = map(int,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: Runtime Error

Solution code:
counter = 0
for i  in range(0, len(candies)-1):
    counter += candies[i+1] + candies[i] - x
    candies[i+1] = x - candies[i]
print counter

Submission status: Runtime Error

Solution code:
# problem C
N, x = map(int, input().split())
num_list = [int(x) for x in input().split()]
if x < num_list[0]:
    count = n - num_list[0]
    num_list[0] = x
else:
    count = 0


for i in range(N-1):
    n = num_list[i] + num_list[i+1]
    if x < n:
        num_list[i+1] = x - num_list[i]
        count += n - x
    else:
        pass
print(count)

Submission status: Runtime Error

Solution code:
t=raw_input().split(" ")
N=t[0]
x=t[1]
a=raw_input().split(" ")
c=0
i=0
ans=0
while 1:
    if a[i]+a[i+1]<=x:
        i=i+1
        continue
    else:
        while a[i]+a[i+1]>x:
            a[i+1]=a[i+1]-1
            ans=ans+1
            if a[i+1]==0:
    i=i+1
    if i+2==N:
        break
print ans