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
#include <iostream>
#include <cstdint>
#include <bitset>

using namespace std;

int64_t oranzada()
{
    uint32_t n, k;
    bitset<500001> data = {};
    cin >> n >> k;

    uint32_t c = 0, s = 0;

    for (size_t i = 0; i < n; i++)
    {
        uint32_t val;
        cin >> val;
        if (data.test(val)) {
            c++;
        }
        else {
            data.set(val);
            s += c;
            k--;
            if (k == 0) return s;
        }
    }

    return -1;
}

int main() {
    std::cout << oranzada() << endl;
}