CF1876F.Indefinite Clownfish

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Pak Chanek has just bought an empty fish tank and he has been dreaming to fill it with his favourite kind of fish, clownfish. Pak Chanek likes clownfish because of their ability to change their genders on demand. Because of the size of his fish tank, Pak Chanek wants to buy exactly kk clownfish to fill the tank.

Pak Chanek goes to the local fish shop. The shop provides nn clownfish numbered from 11 to nn , with clownfish ii having a size of aia_i . Initially, every clownfish in the store does not have an assigned gender, but has the ability to be assigned to two possible clownfish genders, female or male.

The store has a procedure which Pak Chanek should follow to buy clownfish. The shop owner will point at each clownfish sequentially from 11 to nn and for each clownfish, she asks Pak Chanek whether to buy it or not. Each time Pak Chanek is asked, he must declare whether to buy the currently asked clownfish or not, before the shop owner moves on to the next clownfish. If Pak Chanek declares to buy the currently asked clownfish, he must also declare the gender to be assigned to that clownfish immediately. When assigning the gender for the currently asked clownfish, the following conditions must be satisfied:

  • If Pak Chanek assigns it to be female and he has bought a female clownfish before, then the size of the current one must be exactly 11 bigger than the last female one.
  • If Pak Chanek assigns it to be male and he has bought a male clownfish before, then the size of the current one must be exactly 11 smaller than the last male one.

Pak Chanek wants to buy exactly kk clownfish such that:

  • There is at least one female clownfish and one male clownfish.
  • Among the kk clownfish Pak Chanek buys, the mean size of the female clownfish is equal to the mean size of the male clownfish.

Let ll and rr respectively be the minimum and maximum index of a clownfish Pak Chanek buys. What is the minimum possible value of rlr-l ?

输入格式

The first line contains two integers nn and kk ( 2kn21052 \leq k \leq n \leq 2\cdot10^5 ) — the number of clownfish in the shop and the number of clownfish Pak Chanek has to buy.

The second line contains nn integers a1,a2,a3,,ana_1,a_2,a_3,\ldots,a_n ( 1ain1\leq a_i\leq n ) — the size of each clownfish.

输出格式

An integer representing the minimum possible value of rlr-l . If it is impossible to buy exactly kk clownfish and satisfy the problem's condition, print 1-1 .

输入输出样例

  • 输入#1

    9 6
    2 4 2 3 2 4 1 3 4

    输出#1

    6
  • 输入#2

    6 6
    2 6 5 2 6 5

    输出#2

    -1
  • 输入#3

    5 4
    1 2 3 4 5

    输出#3

    -1

说明/提示

In the first example, Pak Chanek can do the following:

  1. Do not buy clownfish 11 .
  2. Buy clownfish 22 and assign it as male.
  3. Buy clownfish 33 and assign it as female.
  4. Buy clownfish 44 and assign it as male.
  5. Buy clownfish 55 and assign it as male.
  6. Do not buy clownfish 66 .
  7. Buy clownfish 77 and assign it as male.
  8. Buy clownfish 88 and assign it as female.
  9. Do not buy clownfish 99 .

Then, we get that:

  • The mean size among the 22 female clownfish Pak Chanek buys is 2+32=2.5\frac{2+3}{2} = 2.5 .
  • The mean size among the 44 male clownfish Pak Chanek buys is 4+3+2+14=2.5\frac{4+3+2+1}{4} = 2.5 .
  • l=2l=2 , r=8r=8 , rl=6r-l=6 .

There are no better strategies.

首页