#include <iostream>
#include <set>
#include <vector>
using namespace std;
int oranzady[500010];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie();
int ile_oranzad, ile_roznych_chce;
cin >> ile_oranzad >> ile_roznych_chce;
set<int> uzyte;
cin >> oranzady[0];
uzyte.insert(oranzady[0]);
int kroki = 0;
for (int i = 1; i < ile_oranzad; i++)
{
int oranzada;
cin >> oranzada;
if (!uzyte.count(oranzada))
{
int ile_krokow = i - (uzyte.size());
uzyte.insert(oranzada);
kroki += ile_krokow;
}
}
if (uzyte.size() >= ile_roznych_chce)
cout << kroki << endl;
else
cout << -1 << endl;
}
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 | #include <iostream> #include <set> #include <vector> using namespace std; int oranzady[500010]; int main() { ios_base::sync_with_stdio(0); cin.tie(); int ile_oranzad, ile_roznych_chce; cin >> ile_oranzad >> ile_roznych_chce; set<int> uzyte; cin >> oranzady[0]; uzyte.insert(oranzady[0]); int kroki = 0; for (int i = 1; i < ile_oranzad; i++) { int oranzada; cin >> oranzada; if (!uzyte.count(oranzada)) { int ile_krokow = i - (uzyte.size()); uzyte.insert(oranzada); kroki += ile_krokow; } } if (uzyte.size() >= ile_roznych_chce) cout << kroki << endl; else cout << -1 << endl; } |
English