개발/C++

[BOJ] 1966 - 프린터 큐

#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

struct TestCase {
    int n;
    int m;
    vector<int> priority;
};

void simulateQueue(TestCase testCase){
    int m = testCase.m;
    vector<int> priority = testCase.priority;

    int result = 0;
    vector<int> sortedPriority;
    sortedPriority.assign(priority.begin(), priority.end());
    sort(sortedPriority.begin(), sortedPriority.end(), greater<int>());

    int count = 0;
    while(!priority.empty()){
        if(sortedPriority[0] == priority[0]){
            count++;
            if(m == 0) {
                cout << count << "\n";
                return;
            }
            sortedPriority.erase(sortedPriority.begin());
            priority.erase(priority.begin());
            m--;
        } else {
            priority.push_back(priority[0]);
            priority.erase(priority.begin());
            if(m == 0) {
                m = priority.size() - 1;
            } else {
                m--;
            }
        }
    }
    cout << result << "\n";
}

int main(){
    int size;
    cin >> size;
    TestCase* t = new TestCase[size];

    for(int i = 0; i < size; i++){
        cin >> t[i].n >> t[i].m;
        for(int j = 0; j < t[i].n; j++){
            int tmp;
            cin >> tmp;
            t[i].priority.push_back(tmp);
        }
    }

    for(int i = 0; i < size; i++){
        simulateQueue(t[i]);
    }
}

'개발 > C++' 카테고리의 다른 글

[BOJ] 2108 - 통계학  (0) 2022.02.03
[BOJ] 1978 - 소수 찾기  (0) 2022.02.03
[BOJ] 1929 - 소수 구하기  (0) 2022.02.03
[BOJ] 1920 - 수찾기  (0) 2021.12.30
[BOJ] 1874 - 스택수열  (0) 2021.12.30