From 82d3d4263103b68c055658277a097d0bef4264f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EC=8B=A0=EC=A7=80?= <101992179+ksinji@users.noreply.github.com> Date: Wed, 5 Nov 2025 23:33:33 +0900 Subject: [PATCH] =?UTF-8?q?[20251105]=20PGM=20/=20LV2=20/=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=EC=84=B8=EC=8A=A4=20/=20=EA=B0=95=EC=8B=A0=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...04\353\241\234\354\204\270\354\212\244.md" | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 "ksinji/202511/5 PGM \355\224\204\353\241\234\354\204\270\354\212\244.md" diff --git "a/ksinji/202511/5 PGM \355\224\204\353\241\234\354\204\270\354\212\244.md" "b/ksinji/202511/5 PGM \355\224\204\353\241\234\354\204\270\354\212\244.md" new file mode 100644 index 00000000..24222df2 --- /dev/null +++ "b/ksinji/202511/5 PGM \355\224\204\353\241\234\354\204\270\354\212\244.md" @@ -0,0 +1,33 @@ +```java +import java.util.*; + +class Solution { + public int solution(int[] priorities, int location) { + int[] cnt = new int[10]; + for (int p : priorities) cnt[p]++; + + ArrayDeque q = new ArrayDeque<>(); + for (int i = 0; i < priorities.length; i++) q.offer(new int[]{priorities[i], i}); + + int cur = 9; + while (cur > 0 && cnt[cur] == 0) cur--; + + int order = 0; + while (!q.isEmpty()) { + int[] doc = q.poll(); + int p = doc[0], idx = doc[1]; + + if (p == cur) { + order++; + cnt[p]--; + if (idx == location) return order; + while (cur > 0 && cnt[cur] == 0) cur--; + } else { + q.offer(doc); + } + } + return -1; + } +} + +```