0

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)

18th Aug 2018, 3:36 PM
Danish
2 Answers
+ 1
May be you should add tag "python" ? there would be more chance that you will be helped
18th Aug 2018, 3:41 PM
Roman Khristoforov
Roman Khristoforov - avatar
0
This is not language based problem Thanks anyway
18th Aug 2018, 3:58 PM
Danish