[20251122] BOJ / G5 / 두 용액 #1476
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.
🧷 문제 링크
https://www.acmicpc.net/problem/2470
🧭 풀이 시간
40분
👀 체감 난이도
✏️ 문제 설명
두 용액을 고르는데, 두 용액의 합이 0과 제일 가까운 경우를 출력하라
🔍 풀이 방법
인덱스 하나씩 고정해놓고 반대편꺼 찾을 때, 이분 탐색
⏳ 회고
아직도 언제는
left<=right고 언제는left<right인지 모르겠네어떤 걸 써야 할까?
left <= right를 쓰는 경우:
배열에서 정확한 값을 찾을 때
범위를 [0, len(arr)-1]로 초기화할 때
mid 값을 확인 후 완전히 제외하고 싶을 때
left < right를 쓰는 경우:
lower_bound/upper_bound (이상/초과 값) 찾을 때
범위를 [0, len(arr))로 초기화할 때
최종 답이 left 또는 right 자체일 때
라네