I am stuck in this problem please help
This is problem statement You are given a stack of N integers such that the first element represents the top of the stack and the last element represents the bottom of the stack. You need to pop at least one element from the stack. At any one moment, you can convert stack into a queue. The bottom of the stack represents the front of the queue. You cannot convert the queue back into a stack. Your task is to remove exactly K elements such that the sum of the K removed elements is maximised. Input format : The first line consists of two space-separated integers N and K. The second line consists of N space-separated integers denoting the elements of the stack. Here is my solution. Help me where I m wrong n , c = input().split() n , c = int(n) , int(c) arr = [int(i) for i in input().split()] sum = 0 while arr[0] >= arr[-1] and c > 0: sum = sum + arr[0] arr = arr[1:] c = c - 1 while c > 0: sum += arr[-1] arr = arr[0:-1] c = c - 1 print (sum)