Maximise top
Description
You are given a stack of N integers. In one operation, you can either pop an element from the stack or push any popped element into the stack. You need to maximize the top element of the stack after performing exactly K operations. If the stack becomes empty after performing K operations and there is no other way for the stack to be non-empty, print -1.
Input
Input Fomat
The first line of input consists of two space-separated integers N and K.
The second line of input consists N space-separated integers denoting the elements of the stack. The first element represents the top of the stack and the last element represents the bottom of the stack.
Constraints
N < 2000000
K < 10^9
Numbers of stack <10^18
(Note that numbers are very large)
Output
Output Format
Print the maximum possible top element of the stack after performing exactly K operations.
Comments
Post a Comment