Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6560 |

@blackshadows | 6400 |

@mb1973 | 5777 |

@Quandray | 5275 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 5074 |

@kirtidee18 | 4408 |

@sanjay05 | 3762 |

@mantu_singh | 3666 |

@gfgaccount | 3605 |

@marius_valentin_dragoi | 3525 |

Complete Leaderboard | |

Handle | Score |

@anish5256 | 991 |

@vimleshpratapsingh321 | 980 |

@skj7 | 953 |

@kanewilliamson123 | 894 |

@pradeeppatidar1999 | 868 |

@akhileshkumar562002 | 862 |

@wallflowe101 | 826 |

@pd420786 | 813 |

@infilooop | 800 |

@bunnybug320 | 796 |

@nikhilkushwah280 | 796 |

Complete Leaderboard |

Given an array sequence [A1 , A2 ...An], the task is to find the maximum possible sum of increasing subsequence S of length K such that Si1<=Si2<=Si3.........<=Sin.

**Example 1:**

**Input:**
N = 8 K = 3
A[] = {8 5 9 10 5 6 19 8}
**Output: **38
**Explanation:**
Possible increasing subsequence of
length 3 with maximum possible
sum is 9 10 9.

**Example 2:**

**Input:
**N = 2,K = 2
A[] = {10 5}
**Output: **-1
**Explanation:
**Can't make any increasing subsequence
of length 2.

**Your Task:**

You don't need to read or print anything. Your task is to complete the function **max_sum()** which takes sequence A as the first parameter and K as the second parameter and returns the maximum possible sum of K-length increasing subsequnece. If not possible return -1.

**Expected Time Complexity: **O(max(Ai) * n * log(max(Ai)))

**Expected Space Complexity: **O(max(Ai))

**Contraints:**

1 <= n <= 100

1 <= A_{i} <= 100000

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

Maximum Sum Subsequence of length k

...