Non-decreasing subsequence
Easy Accuracy: 4.65% Submissions: 43 Points: 2

Given a sequence of n integers, the task is to find out the non-decreasing subsequence of length k with minimum sum. If no sequence exists output -1.

Example 1:

Input: N = 10, K = 3, arr[] = {58, 12, 
       11, 12, 82, 30, 20, 77, 16, 86}
Output: 39
Explanation: {11 + 12 + 16}
Example 2:
Input: N = 10, K = 4, arr[] = {58, 12,
11, 12, 82, 30, 20, 77, 16, 86}
Output: 120
Explanation: {11 + 12 + 16 + 77}


Your Task:  
You don't need to read input or print anything. Complete the function minSum() which takes N, K and array arr as input parameters and returns the integer value

Expected Time Complexity: O(N*K)
Expected Auxiliary Space: O(N*K)

Constraints:
1 ≤ N, K ≤ 103

1 ≤ arr[i] ≤ 105

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.