-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChiefHopper.py
More file actions
39 lines (26 loc) · 786 Bytes
/
ChiefHopper.py
File metadata and controls
39 lines (26 loc) · 786 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the chiefHopper function below.
def chiefHopper(arr):
# Do backward tracking
# Assumption: energy left in the end is zero
# so that we can get minimum value at the start
# by going backwards
new_energy = 0
# Calculate energy before jumping on each building
# starting from the last building
for i in range(len(arr) - 1, -1, -1):
new_energy = math.ceil((new_energy + arr[i]) / 2)
return new_energy
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
n = int(input())
arr = list(map(int, input().rstrip().split()))
result = chiefHopper(arr)
# print(result)
fptr.write(str(result) + '\n')
fptr.close()