13. Maximum Sum of Elements Not Part of LIS
β GFG solution to the Maximum Sum of Elements Not Part of LIS problem: find maximum sum of elements not in the Longest Increasing Subsequence using binary search optimization. π
π§© Problem Description
π Examples
Example 1
Input: arr[] = [4, 6, 1, 2, 3, 8]
Output: 10
Explanation: The LIS could be [1, 2, 3, 8] with sum 14.
The elements not in LIS are [4, 6] with sum 10.
Total sum = 24, LIS sum = 14, so answer = 24 - 14 = 10.Example 2
Input: arr[] = [5, 4, 3, 2, 1]
Output: 14
Explanation: The LIS is [1] (or any single element) with sum 1.
The elements not in LIS are [5, 4, 3, 2] with sum 14.
Total sum = 15, LIS sum = 1, so answer = 15 - 1 = 14.π Constraints
β
My Approach
Binary Search + Cumulative Sum Tracking
π Time and Auxiliary Space Complexity
π§βπ» Code (C++)
π§βπ» Code (Java)
π Code (Python)
π§ Contribution and Support
πVisitor Count
Last updated