← 返回 amazon 的题目列表Split into k Non-overlapping Subsequences with Max/Min Cost
类型:online_judge
Given an integer array c of length n, split it into k non-overlapping subsequences such that the cost of a subsequence is the sum of its first and last elements. If a subsequence has only one element, its cost is twice that element. Find the maximum and minimum costs of splitting the array. The conditions are 1 <= k <= n <= 10^5, and the required time complexity is O(nlogn).
Example
Input
[1, 2, 3, 4], 2