Geeksforgeeks

Error

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:39Explanation: {11 + 12 + 16}

**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

1 ≤

1 ≤

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

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

YesLoading...

Non-decreasing subsequence

...