#include <iostream>
#include <algorithm>
using namespace std;
long long t[500100];
int main()
{
std::ios_base::sync_with_stdio(0);
long long n, k, wynik=0, brak, bottle;
cin>>n>>k;
brak=0;
for(long long i=0; i<n; ++i)
{
cin>>bottle;
if(brak<k)
if(t[bottle]==0)
{
wynik+=i-brak;
++brak;
}
++t[bottle];
}
if(brak<k)
cout<<-1;
else if(wynik>=1)
cout<<wynik;
else cout<<0;
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 | #include <iostream> #include <algorithm> using namespace std; long long t[500100]; int main() { std::ios_base::sync_with_stdio(0); long long n, k, wynik=0, brak, bottle; cin>>n>>k; brak=0; for(long long i=0; i<n; ++i) { cin>>bottle; if(brak<k) if(t[bottle]==0) { wynik+=i-brak; ++brak; } ++t[bottle]; } if(brak<k) cout<<-1; else if(wynik>=1) cout<<wynik; else cout<<0; return 0; } |
English