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<stdio.h>
#include<algorithm>
using namespace std;
int w[101000], n, m, c;
int main(){
int i, t;
scanf("%d", &n);
for (i = 1; i <= n; i++){
scanf("%d", &w[i]);
}
scanf("%d", &m);
if (m <= n){
printf("%d\n", w[m]);
return 0;
}
sort(w + 1, w + n + 1);
for (i = 1; i <= n; i++){
if (i == 1 || w[i] != w[i - 1])c++;
}
for (i = 1; i <= n; i++)if (w[i] >= c)break;
t = i;
if (t == n + 1 || w[t] - c > m - (n+1)){
printf("%d\n", m - (n + 1) + c);
}
else printf("%d\n", w[t]);
}
# | 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... |