Marc's Cakewalk

  • + 0 comments
    #!/bin/python3
    
    import os
    
    def marcsCakewalk(calorie):
        # Sort the calorie list in descending order
        calorie.sort(reverse=True)
        
        # Initialize the total distance to 0
        total_distance = 0
        
        # Calculate the minimum distance Marc needs to walk
        for i in range(len(calorie)):
            total_distance += calorie[i] * (2 ** i)
        
        return total_distance
    
    if __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()