Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 5
- # 6 2 3 5 1
- # 4 5 6 3
- # count boxes
- n = str(input())
- if not n.isnumeric() or not (2 <= int(n) <= 1000):
- raise Exception('Error condition n')
- # count candies in boxes
- ai = str(input()).split(' ')
- if len(ai) < int(n):
- raise Exception('Error condition ai count')
- for a in ai:
- if not str(a).isnumeric() or not (0 <= int(a) <= 1000):
- raise Exception(f'Error condition a[{a}]')
- # limit candies in boxes i-1
- bi = str(input()).split(' ')
- if len(bi) < int(int(n) - 1):
- raise Exception('Error condition bi count')
- i = 0
- act = 0
- for b in bi:
- if not str(b).isnumeric() or not (0 <= int(b) <= 1000):
- raise Exception(f'Error condition b[{b}]')
- a1 = int(ai[i])
- a2 = int(ai[i + 1])
- clr = (a1 + a2) - int(b)
- act += clr
- if a1 > a2:
- if clr <= a1:
- ai[i] = a1 - clr
- else:
- ai[i] = 0
- ai[i + 1] = a2 - (clr - a1)
- else:
- if clr <= a2:
- ai[i + 1] = a2 - clr
- else:
- ai[i + 1] = 0
- ai[i] = a1 - (clr - a2)
- i += 1
- print(act)
Add Comment
Please, Sign In to add comment