diff --git a/alstjr7437/README.md b/alstjr7437/README.md index ace1a9b..035553e 100644 --- a/alstjr7437/README.md +++ b/alstjr7437/README.md @@ -4,5 +4,6 @@ |:----:|:---------:|:----:|:-----:|:----:| | 1차시 | 2025.03.26 | BFS | [미로 탐색](https://www.acmicpc.net/problem/2178)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/2| | 2차시 | 2025.04.08 | Heap | [최대힙](https://www.acmicpc.net/problem/11279)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/7| -| 3차시 | 2025.04.30 | 투포인터 | [최대힙](https://www.acmicpc.net/problem/7795)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/17| +| 3차시 | 2025.04.30 | 투포인터 | [먹을 것인가 먹힐 것인가](https://www.acmicpc.net/problem/7795)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/17| +| 4차시 | 2025.05.13 | 구현 | [후보 추천하기](https://www.acmicpc.net/problem/1713)|https://github.com/AlgoLeadMe/AlgoLeadMe-14/pull/24| --- diff --git "a/alstjr7437/\352\265\254\355\230\204/BOJ_1713.swift" "b/alstjr7437/\352\265\254\355\230\204/BOJ_1713.swift" new file mode 100644 index 0000000..9e46e9d --- /dev/null +++ "b/alstjr7437/\352\265\254\355\230\204/BOJ_1713.swift" @@ -0,0 +1,29 @@ +let N = Int(readLine()!)! +let totalCount = Int(readLine()!)! +let recommend = readLine()!.split(separator: " ").map { Int(String($0))! } + +var result: [Int: (recommendCount: Int, time: Int)] = [:] +var currentTime = 0 + +for student in recommend { + if result[student] != nil { + result[student]!.recommendCount += 1 + } else { + if result.count < N { + result[student] = (1, currentTime) + } else { + let removeValue = result.min { + if $0.value.recommendCount == $1.value.recommendCount { + return $0.value.time < $1.value.time + } + return $0.value.recommendCount < $1.value.recommendCount + }!.key + + result.removeValue(forKey: removeValue) + result[student] = (1, currentTime) + } + } + currentTime += 1 +} + +print(result.keys.sorted().map { String($0) }.joined(separator: " "))