#include <bits/stdc++.h> #define ll long long using namespace std; int main(){ ios_base::sync_with_stdio(0); ll n, k; cin>>n>>k; vector<bool> tab(n+10); ll pt = 0; ll wyn = 0; for(ll i = 0; i < n; i++){ ll a; cin>>a; if(pt==k) continue; if(!tab[a]){ tab[a] = 1; wyn+=(i-pt); pt++; } } if(pt!=k) cout<<-1<<'\n'; else cout<<wyn<<'\n'; 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 | #include <bits/stdc++.h> #define ll long long using namespace std; int main(){ ios_base::sync_with_stdio(0); ll n, k; cin>>n>>k; vector<bool> tab(n+10); ll pt = 0; ll wyn = 0; for(ll i = 0; i < n; i++){ ll a; cin>>a; if(pt==k) continue; if(!tab[a]){ tab[a] = 1; wyn+=(i-pt); pt++; } } if(pt!=k) cout<<-1<<'\n'; else cout<<wyn<<'\n'; return 0; } |