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 <iostream>
#include <fstream>
#include <string>
#include <string.h>
#include <queue>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <limits.h>
typedef long long ll;
using namespace std;
int n, m, t;
int main()
{
#ifdef _CONSOLE
freopen("input.txt", "r", stdin);
#endif
int n;
cin >> n;
vector<int> vi(n);
for (int i = 0; i < n; i++){
cin >> vi[i];
}
cin >> m;
if (m <= n){
cout << vi[m - 1] << endl;
return 0;
}
sort(vi.begin(), vi.end());
vi.resize(unique(vi.begin(), vi.end()) - vi.begin());
vector<int>::iterator itor = lower_bound(vi.begin(), vi.end(), vi.size());
if (itor == vi.end()){
cout << (m - n) + (vi.size() - 1) << endl; // 무한
}
else{
if ((*itor - vi.size() + 1) + n <= m) // 아닐때
cout << *itor << endl;
else{
cout << (m - n) + (vi.size() - 1) << endl; // 무한
}
}
}
# | 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... |