We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#!/bin/python3importosdefmarcsCakewalk(calorie):# Sort the calorie list in descending ordercalorie.sort(reverse=True)# Initialize the total distance to 0total_distance=0# Calculate the minimum distance Marc needs to walkforiinrange(len(calorie)):total_distance+=calorie[i]*(2**i)returntotal_distanceif__name__=='__main__':fptr=open(os.environ['OUTPUT_PATH'],'w')n=int(input().strip())calorie=list(map(int,input().rstrip().split()))result=marcsCakewalk(calorie)fptr.write(str(result)+'\n')fptr.close()
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Marc's Cakewalk
You are viewing a single comment's thread. Return to all comments →