diff --git "a/LiiNi-coder/202511/18 PGM \355\224\204\353\241\234\354\204\270\354\212\244.md" "b/LiiNi-coder/202511/18 PGM \355\224\204\353\241\234\354\204\270\354\212\244.md" new file mode 100644 index 00000000..5fdbb7e1 --- /dev/null +++ "b/LiiNi-coder/202511/18 PGM \355\224\204\353\241\234\354\204\270\354\212\244.md" @@ -0,0 +1,38 @@ +```java +import java.util.*; + +class Solution { + public int solution(int[] priorities, int location) { + PriorityQueue pq = new PriorityQueue<>( Collections.reverseOrder()); + for(int p : priorities){ + pq.offer(p); + } + int printedCount = 0; + Deque queue = new ArrayDeque<>(); + for(int i = 0; i < priorities.length; i++){ + queue.offerLast(new int[]{ i, priorities[i] }); + } + + while(!queue.isEmpty()){ + int[] now = queue.pollFirst(); + int index = now[0]; + int pri = now[1]; + + if(pri == pq.peek()){ + pq.poll(); + printedCount++; + if(index == location){ + return printedCount; + } + } + + //다시 큐 보내기 + else { + queue.offerLast(now); + } + } + return printedCount; + } +} + +```