This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int N, M;
int S[50001];
set<int> T;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
cin >> N;
for (int i=1; i<=N; i++){
cin >> S[i];
T.insert(S[i]);
}
cin >> M;
if (M <= N){
cout << S[M] << endl;
return 0;
}
if ((signed) T.size() > *T.rbegin()){
cout << T.size() + M - N - 1 << endl;
return 0;
}
int i = N+1;
while (1){
if (i == M){
cout << T.size() << endl;
return 0;
}
if (T.lower_bound(T.size()) != T.end()){
T.insert(T.size());
i++;
continue;
}
cout << T.size() + M - i << endl;
return 0;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |