[20250320] BOJ / G1 / Lifeguards (Silver) / 권혁준#275
Merged
ShinHeeEul merged 1 commit intomainfrom Mar 20, 2025
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🧷 문제 링크
https://www.acmicpc.net/problem/15589
🧭 풀이 시간
35분

👀 체감 난이도
✏️ 문제 설명
N마리의 라이프가드 소가 있다.
i번째 소는 시각 L[i]에 근무를 시작해서 R[i]에 근무를 마친다.
정확히 한 마리의 소를 해고하려고 할 때, 해고된 이후의 전체 근무 시간을 최대화 해보자.
전체 근무 시간이란, 적어도 한 마리의 소가 근무하고 있는 시간을 의미한다.
🔍 풀이 방법
[사용한 알고리즘]
N마리의 소에 의해서 이벤트가 발생하는 (소가 출근 or 퇴근하는) 시점은 최대 2N개 뿐이다.
시간 순서대로 이벤트를 정렬시키고, 시간 축을 스위핑하며 TreeSet에 근무 중인 소들을 모두 넣어놓는다.
이 TreeSet의 size가 1일 때, 해당 소가 해고되면 근무가 터지게 된다. -> 각 소가 해고되었을 때의 펑크나게 되는 시간을 따로 배열에 저장해놓는다.
스위핑이 끝나면, 마지막에 이 배열을 한 번 돌며 최솟값을 찾아주면 된다.
⏳ 회고
...