/***********PA 2021***********/
/******Autor: Jakub Bąba******/
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k, i = 0, input;
long long dod = 0, wynik = 0;
set<int> unikalne;
cin >> n >> k;
while (i<n && unikalne.size() < k)
{
cin >> input;
if (unikalne.count(input))
dod++;
else
{
unikalne.insert(input);
wynik += dod;
}
i++;
}
if (unikalne.size() == k)
cout << wynik;
else
cout << "-1";
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 | /***********PA 2021***********/ /******Autor: Jakub Bąba******/ #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k, i = 0, input; long long dod = 0, wynik = 0; set<int> unikalne; cin >> n >> k; while (i<n && unikalne.size() < k) { cin >> input; if (unikalne.count(input)) dod++; else { unikalne.insert(input); wynik += dod; } i++; } if (unikalne.size() == k) cout << wynik; else cout << "-1"; return 0; } |
English