Merge Stone Problem:You have n piles of stones in a line. For example, [4, 1, 2] means 3 piles of stone, the first pile has 4 stones, the second pile has 1 stone, and so on. You task is to merge n piles of stones into 1 pile, and make sure the number of stones you moved is minimal. Restrictions:Can only merge adjacent 2 piles into 1 pile;To merge 2 adjacent piles into 1 pile, you actually will move all the stones in these 2 piles.My algorithm:Merge two adjacent piles which have the least sum, consider this as optimal choice. Do this until there is 1 pile of stone left.Code:score = 0while len(A) > 1:    kv, ki = float('inf'), 0    for i in range(len(A)-1):        if A[i] + A[i+1] < kv:            kv, ki = A[i] + A[i+1], i    score += kv    A = A[:ki] + [kv] + A[ki+2:]return scorePS: I know my greedy algorithm is not working by running unit tests provided by others. However, the test I failed is too large, I can not verify by hand which choice the greedy algorithm I made is wrong.
Why my greedy algorithm not working for merge stone problem
python;array