//
// main.cpp
// Oranżada
//
// Created by Andy Bachleda-Curuś on 07/12/2021.
//
#include <iostream>
#include <vector>
#include <set>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long n, k, czas = 0, licz = 0;
cin >> n >> k;
vector <long long> but(n);
set <long long> s;
for(int i = 0; i < n; i++)
{
cin >> but[i];
}
for(int i = 0; i < n; i++)
{
if(s.count(but[i]) == 0)
{
czas += i - licz;
licz++;
}
s.insert(but[i]);
if(licz == k)
break;
}
if(licz == k)
cout << czas << endl;
else
cout << "-1" << endl;
return 0;
}
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 | // // main.cpp // Oranżada // // Created by Andy Bachleda-Curuś on 07/12/2021. // #include <iostream> #include <vector> #include <set> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); long long n, k, czas = 0, licz = 0; cin >> n >> k; vector <long long> but(n); set <long long> s; for(int i = 0; i < n; i++) { cin >> but[i]; } for(int i = 0; i < n; i++) { if(s.count(but[i]) == 0) { czas += i - licz; licz++; } s.insert(but[i]); if(licz == k) break; } if(licz == k) cout << czas << endl; else cout << "-1" << endl; return 0; } |
English