https://school.programmers.co.kr/learn/courses/30/lessons/42587
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
using namespace std;
int solution(vector<int> priorities, int location) {
int answer = 0;
deque<pair<int, int>> q;
for (int i = 0; i < priorities.size(); ++i)
q.emplace_back(make_pair(i, priorities[i]));
auto max = *max_element(q.begin(), q.end(), [](pair<int, int> a, pair<int, int> b) { return a.second < b.second; });
while (true)
{
auto pp = q.front();
q.pop_front();
if (pp.second == max.second)
{
++answer;
if (pp.first == location) break;
max = *max_element(q.begin(), q.end(), [](pair<int, int> a, pair<int, int> b) { return a.second < b.second; });
}
else
q.emplace_back(pp);
}
return answer;
}
'Coding Test > Programmers' 카테고리의 다른 글
[Programmers] (완전탐색) Lv 2. 피로도 (0) | 2023.06.16 |
---|---|
[Programmers] (2018 KAKAO BLIND RECRUITMENT) Lv 2. [1차] 뉴스 클러스터링 (0) | 2023.06.16 |
[Programmers] Lv 2. 할인 행사 (0) | 2023.06.16 |
[Programmers] (스택/큐) Lv 2. 기능개발 (0) | 2023.06.16 |
[Programmers] (2019 카카오 개발자 겨울 인턴십) Lv 2. 튜플 (0) | 2023.06.16 |
댓글