codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

222A.md (1538B)


      1 Source: https://codeforces.com/problemset/problem/222/A
      2 
      3 A. Shooshuns and Sequence
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps:
     22 
     23 1. Find the number that goes *k*-th in the current sequence and add the same number to the end of the sequence;
     24 2. Delete the first number of the current sequence.
     25 
     26 The shooshuns wonder after how many operations all numbers on the board will be the same and whether all numbers will ever be the same.
     27 
     28 Input
     29 
     30 The first line contains two space-separated integers *n* and *k* (1 ≤ *k* ≤ *n* ≤ 105).
     31 
     32 The second line contains *n* space-separated integers: *a*1, *a*2, ..., *a**n* (1 ≤ *a**i* ≤ 105) — the sequence that the shooshuns found.
     33 
     34 Output
     35 
     36 Print the minimum number of operations, required for all numbers on the blackboard to become the same. If it is impossible to achieve, print -1.
     37 
     38 Examples
     39 
     40 Input
     41 
     42 ```
     43 3 2  
     44 3 1 1
     45 ```
     46 
     47 Output
     48 
     49 ```
     50 1
     51 ```
     52 
     53 Input
     54 
     55 ```
     56 3 1  
     57 3 1 1
     58 ```
     59 
     60 Output
     61 
     62 ```
     63 -1
     64 ```
     65 
     66 Note
     67 
     68 In the first test case after the first operation the blackboard will have sequence [1, 1, 1]. So, one operation is enough to make all numbers the same. Thus, the answer equals one.
     69 
     70 In the second test case the sequence will never consist of the same numbers. It will always contain at least two distinct numbers 3 and 1. Thus, the answer equals -1.