MNMX - using ".Pop"

A cake walk problem :
however I would like to know why the following solution using pop doesn’t work?

for tc in range(int(input())):
    size_array = int(input()) #Just for the heck of it
    a1 = list(map(int,input().split(' ')))
    i = 0
    cost = 0
    while len(a1)!=1:

        if a1[i]>a1[i+1]:
            cost = cost + a1[i+1]
        elif a1[i]<a1[i+1]:
            cost = cost + a1[i]


Intention should have been to remove adjacent elements of the minimum value in array, so that ultimately min of the array remains only element in the array.
so the answer would be minelement * (nosOfElement - 1)
In your case you are eliminating one of the adjacent element sequentially and remained element - which may not be the min of the array - is added to the cost leading to a value leading to a value greater then minelement * (nosOfElement - 1)

1 Like