#include<iostream> using namespace std; #define MAXN 500000 int n, k; // vector<int> seq; bool seen[MAXN]; int main() { cin >> n >> k; unsigned long long ans = 0; int types = 0; for(int i = 0; i < n; i++) { int botno; cin >> botno; // seq.push_back(botno); if(seen[botno]) { continue; } seen[botno] = true; ans += i - types; if(++types == k) { cout << ans; cout.flush(); return 0; } } cout << -1; cout.flush(); }
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 | #include<iostream> using namespace std; #define MAXN 500000 int n, k; // vector<int> seq; bool seen[MAXN]; int main() { cin >> n >> k; unsigned long long ans = 0; int types = 0; for(int i = 0; i < n; i++) { int botno; cin >> botno; // seq.push_back(botno); if(seen[botno]) { continue; } seen[botno] = true; ans += i - types; if(++types == k) { cout << ans; cout.flush(); return 0; } } cout << -1; cout.flush(); } |