개발/C++
[BOJ] 1966 - 프린터 큐
차파랑
2022. 2. 3. 22:38
#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]);
}
}