Non-decreasing subsequence
Medium Accuracy: 18.06% Submissions: 428 Points: 4

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 sum.

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

Constraints:
1 ≤ N, K ≤ 103

1 ≤ arr[i] ≤ 105

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.


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.

Non-decreasing subsequence

Output Window