1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <typeinfo>

#define c_plus_plus std
#define QED return 0
#define NOT_QED return -1
#define CNU return
#define kiedy_kliknieto_zielona_flage int main()

#define ll long long
#define mp make_pair
#define str string
#define vec vector
#define pb push_back
#define foru(u, n) for(int u=0;u<n;u++)
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807LL
#define ir(a, b, x) ((a<=x)&&(x<=b))
#define f first
#define s second
#define ll long long
#define vll vec<ll>

using namespace c_plus_plus;

#define N 500000

ll n;
ll k;

bool usd[N];
ll shlf[N];

kiedy_kliknieto_zielona_flage
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n;
    cin >> k;

    foru(i, n) {cin >> shlf[i]; usd[i]=false;}

    ll pnt = 0;
    ll ans = 0;
    ll str = 0;

    for(int i=0;i<n;i++){
        if(!usd[shlf[i]]){
            usd[shlf[i]]=true;
            ans += i-str;
            str++;
        }
        if(str==k) {cout << ans; QED;}
    }

    cout << -1;

    QED;
}