#ARC138A. [ARC138A] Larger Score

[ARC138A] Larger Score

Score : 400400 points

Problem Statement

We have an integer sequence of length NN: A=(A1,A2,,AN)A=(A_1,A_2,\cdots,A_N). Below in this problem, let the score of AA be the sum of the first KK terms of AA. Additionally, let ss be the score of the sequence AA given in input.

You can do the following operation any number of times.

  • Choose two adjacent elements of AA and swap them.

Your objective is to make the score at least s+1s+1. Determine whether the objective is achievable. If it is, find the minimum number of operations needed to achieve it.

Constraints

  • 2N4×1052 \leq N \leq 4 \times 10^5
  • 1KN11 \leq K \leq N-1
  • 1Ai1091 \leq A_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN KK

A1A_1 A2A_2 \cdots ANA_N

Output

If the objective is not achievable, print -1. If it is achievable, print the minimum number of operations needed to achieve it.

4 2
2 1 1 2
2

We have s=2+1=3s=2+1=3. The following sequence of operations makes the score at least 44.

  • (2,1,1,2)((2,1,1,2) \to (swap A3A_3 and A4)(2,1,2,1)(A_4)\to (2,1,2,1) \to (swap A2A_2 and A3)(2,2,1,1)A_3)\to (2,2,1,1)

The objective is not achievable in one operation, so the minimum number of operations needed is 22.

3 1
3 2 1
-1
20 13
90699850 344821203 373822335 437633059 534203117 523743511 568996900 694866636 683864672 836230375 751240939 942020833 865334948 142779837 22252499 197049878 303376519 366683358 545670804 580980054
13