#K5461. Optimal Stock Value
Optimal Stock Value
Optimal Stock Value
You are given a list of stock prices and an initial position K (1-indexed) in the list. Your task is to find the maximum stock price from the K-th stock to the last one.
More formally, for an array \(P = [P_1, P_2, \dots, P_N]\) and a given integer \(K\), you must compute:
$$\max_{i=K}^{N} P_i$$where \(P_i\) represents the price of the \(i\)-th stock.
This represents the maximum possible value that can be achieved if you decide to keep selling and buying stocks optimally starting from the current position.
inputFormat
The first line contains an integer \(T\) denoting the number of test cases.
Each test case consists of two lines:
- The first line contains two space-separated integers \(N\) and \(K\), where \(N\) is the total number of stocks and \(K\) is the starting position (1-indexed).
- The second line contains \(N\) space-separated integers, representing the stock prices.
outputFormat
For each test case, print a single line containing one integer — the maximum stock price from the \(K\)-th stock to the \(N\)-th stock.
## sample2
5 2
10 1 5 8 7
4 1
4 3 2 1
8
4
</p>