No.1248 Kth Sum
Problem Statement
You are given a sequence $A$ of length $N$.
You decide to split the sequence $A$ into several subsequences so that the following conditions are satisfied.
- Each element of the sequence $A$ is contained in exactly one subsequence.
- The length of every subsequence after the split is at least $K$.
Find the minimum possible sum of the $K$-th elements from the front of the subsequences after the split.
Input
$N\ K$ $A_1 \ A_2 \dots A_N$
- $1 \le N \le 2 \times 10^5$
- $1 \le K \le N$
- $1 \le A_i \le 10^9$
Output
Output the minimum possible sum of the $K$-th elements from the front of the subsequences after the split. Print a newline at the end.
Sample
Sample 1
Input
4 2 3 4 1 2
Output
3
By splitting into $(3,1)$ and $(4,2)$, the sum of the $2$-nd elements is $1+2=3$.
You can also keep it as the single subsequence $(3,4,1,2)$, but then the sum of the $2$-nd elements is $4$.
Since the length of every subsequence after the split must be at least $2$, you cannot split into $(3,1,2)$ and $(4)$.
Sample 2
Input
3 2 3 4 1
Output
4
In this case, it is not possible to split into two or more subsequences.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
tute7627
leafirby