package leetcode;

/**
 * https://leetcode.com/problems/partition-array-for-maximum-sum/
 */
public class Problem1043 {
    public int maxSumAfterPartitioning(int[] A, int K) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1043 prob = new Problem1043();
        System.out.println(prob.maxSumAfterPartitioning(new int[]{1, 15, 7, 9, 2, 5, 10}, 3)); // 84
    }
}

@@ -12,16 +12,72 @@
 tcode;%0A%0A
+import java.util.Comparator;%0Aimport java.util.TreeSet;%0A%0A
 /**%0A * h
@@ -238,15 +238,436 @@
     
-// TODO
+TreeSet%3CInteger%3E set = new TreeSet%3C%3E(Comparator.reverseOrder());%0A        for (int a : A) %7B%0A            set.add(a);%0A            if (set.size() %3E K) %7B%0A                set.pollLast();%0A            %7D%0A        %7D%0A        int answer = 0;%0A        int prev = 0;%0A        for (int i = 0; i %3C A.length; i++) %7B%0A            if (set.contains(A%5Bi%5D)) %7B%0A                answer += (i - prev) * A%5Bi%5D;%0A                prev = i;%0A            %7D%0A        %7D
 %0A   
@@ -678,17 +678,22 @@
  return 
-0
+answer
 ;%0A    %7D%0A
@@ -885,16 +885,319 @@
 ; // 84%0A
+        System.out.println(prob.maxSumAfterPartitioning(new int%5B%5D%7B1, 15, 7, 10, 2, 5, 9%7D, 3)); // 84%0A        System.out.println(prob.maxSumAfterPartitioning(new int%5B%5D%7B1, 15, 7, 10, 2, 5, 9%7D, 4)); // 87%0A        System.out.println(prob.maxSumAfterPartitioning(new int%5B%5D%7B10, 15, 7, 9, 2, 5, 1%7D, 4)); // 81%0A
     %7D%0A%7D%0A

Update problem 1043