#include <iostream>
#include <algorithm>
#include <vector>
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(NULL);
int N = 0;
int M = 0;
int K = 0;
std::cin >> N >> M >> K;
std::vector<int> arr(M,0);
std::vector<bool> visit(M, false);
for (int i = 0; i < M; ++i)
{
std::cin >> arr[i];
}
std::sort(arr.begin(), arr.end());
int first = 0;
while (K--)
{
int now = 0;
std::cin >> now;
for (int index = std::upper_bound(arr.begin(), arr.end(), now) - arr.begin(); index != arr.size(); ++index)
{
if (!visit[index])
{
visit[index] = true;
std::cout << arr[index] << '\n';
break;
}
}
}
return 0;
}
upper_bound를 이용해서 풀었습니다.
이 전보다 무조건 더 큰 것들로 확인해서 무조건 크지만 가장 근사값으로 확인했습니다.
근사값을 이미 사용했다면 그 다음수를 확인합니다.
'오늘의 알고리즘' 카테고리의 다른 글
[C++] 백준 2580 스도쿠 (0) | 2023.02.07 |
---|---|
[C++] 백준 2981 검문 (0) | 2023.02.01 |
[C++] 백준 2887 행성 터널 (0) | 2022.12.22 |
[C++] 백준 20040 사이클게임 (0) | 2022.12.21 |
[C++] 백준 2568 전깃줄 2 (1) | 2022.12.19 |