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<cstdio>
#include<algorithm>
#define MAX_N 50500
using namespace std;
int n,m,a[MAX_N];
int main() {
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
scanf("%d",&m);
if(m<=n) {
printf("%d\n",a[m]);
return 0;
}
sort(a+1,a+n+1);
int t = n, iter = 1;
for(int i=1;i<n;i++) if(a[i] == a[i+1]) t--;
bool isin = false;
for(int i=1;i<=n;i++) {
if(t == a[i]) {
isin = true;
break;
}
}
if(isin) {
printf("%d\n",t);
return 0;
}
// 2 13 2 2 처럼 constant 가 되어버리는 경우의 수를 처리
m -= n+1;
while(iter <= n && a[iter]<t) iter ++;
if(iter > n) {
printf("%d\n",t+m);
return 0;
}
int length = a[iter] - t;
if(length >= m) printf("%d\n",t+m);
else printf("%d\n",a[iter]);
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... |