[20250820] B형 / SWEA / 온라인마트 / 이강현 #701
Merged
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.
🧷 문제 링크
🧭 풀이 시간
120분
👀 체감 난이도
✏️ 문제 설명
마트에서 특정 카테고리,제품사, 가격이 있는 물건이 있음.
이 물건을 진열대에 추가하거나 삭제하거나 할인할 수 있음.
할인은 특정 카테고리,제품사인 물건들에 동시 적용되고 할인가만큼 가격에서 빠짐.
이때 가격이 0이하가 되면 진열대에서 삭제됨.
추가적으로 옵션에 따라 모든 물건,특정 카테고리, 특정 제품사의 물건들중 가장 싼 물건들을 최대 5개까지 보여줄 수 있음.
🔍 풀이 방법
자료구조 범벅, lazy update
할인할때 바로 가격에 적용하지말고 할인하는 그 양을 저장해둠.
그리고 새로운 물건이 들어올 때, 누적할인값만큼 더해주고 진열대에 등록함.
실제 가격을 비교하는 로직에서 전체 물건에 대해서 누적할인값을 빼면 결과적으로 각각에 적용되는 할인값이 잘 적용된 상태임.
⏳ 회고
ㅅㅂ 이걸 어캐 생각해