Skip to content
This repository was archived by the owner on Mar 18, 2024. It is now read-only.

[2023-09-25] sumin #267 #279

Merged
merged 1 commit into from
Sep 26, 2023
Merged

[2023-09-25] sumin #267 #279

merged 1 commit into from
Sep 26, 2023

Conversation

ksumini
Copy link
Contributor

@ksumini ksumini commented Sep 25, 2023

PR Summary

풀이시간 : 20분

<input>

  • n: 지방의 수(N은 3 이상 10,000)
  • 지방의 예산요청을 표현하는 N개의 정수(값들은 모두 1 이상 100,000 이하)
  • m: 총 예산(N 이상 1,000,000,000 이하)

<solution>

  1. 이분 탐색을 통해 정수 상한액을 찾는다. (최적의 상한액을 찾기 위해 범위를 좁혀나가기)
  • 정수 상한액보다 더 많은 예산 요청을 한 경우 -> 해당 지방은 상한액을 배정한다.
  • 정수 상한액 이하의 예산 요청을 한 경우 -> 해당 지방은 요청 금액을 배정한다.
  1. 각 지방에 모두 예산을 배정한 후 left 또는 right를 조정해 가능한 최대의 총 예산을 사용하는 방법을 찾는다.
  • 배정한 예상의 총합이 총 예산보다 작거나 같면, left를 증가시켜 정수 상한액을 증가시킴으로써 배정할 예산의 총합을 더 키운다.
  • 배정한 예상의 총합이 총 예사보다 크다면, right를 증가시켜 정수 상한액을 줄이고 배정할 예산의 총합도 줄여준다.
  1. 최종적으로 배정된 예산들 중 최댓값(정수 상한액)인 정수를 출력한다.

<시간복잡도>
O(nlogn)

@ksumini ksumini added the BOJ label Sep 25, 2023
@ksumini ksumini self-assigned this Sep 25, 2023
@ksumini ksumini linked an issue Sep 25, 2023 that may be closed by this pull request
Copy link
Contributor

@zsmalla zsmalla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기서는 조건 만족 여부를 따로 빼진 않으셨군요 😂 사실 만족 여부가 간단해서 이 구조도 보기에 깔끔해서 전혀 이해가 어렵지 않았습니다! 고생하셨습니다 수민님!

mid = (left+right) // 2 # 정수 상한액
tot = 0 # 배정한 예산의 총합
for city in cities:
if city > mid: # 1) 상한액 이상의 예산 요청을 한 경우
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

피드백 드릴게 이런 거 밖에 없지만.. 파이썬으로 코테 볼때는 pythonic하게 짜는 것도 중요하다고 한 것 같아서 이런 부분은 tot += mid if city > mid else city 이런 식으로 짜려고 노력하는 편입니다!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋은 의견인것 같습니다 지수님!!!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

조건대로 짜고 최적화를 안해서 그런가봐요😂 담부턴 좀 더 파이써닉하게 최적화하겠습니당 :)

Copy link
Member

@Woo-Yeol Woo-Yeol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

대체적인 풀이 내용이 유사하여 큰 피드백은 없습니다. 다만 마지막 right를 반환하는 부분이 지수님의 풀이와 유사하여서 지수님께 질문을 남겼었는데 다시 한 번 천천히 생각해보니 최대 값을 찾기 위해서 right를 반환하는 방법이 효율적일 것 같다는 것을 깨달았네요! 감사합니다 수민님!!

Copy link
Contributor

@limstonestone limstonestone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다람쥐!!
문제 설명도 잘해주셔서 감사합니당 ㅎ

mid = (left+right) // 2 # 정수 상한액
tot = 0 # 배정한 예산의 총합
for city in cities:
if city > mid: # 1) 상한액 이상의 예산 요청을 한 경우
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋은 의견인것 같습니다 지수님!!!

@ksumini ksumini merged commit 4d9b0bb into main Sep 26, 2023
@ksumini ksumini deleted the sumin-#267 branch September 26, 2023 10:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BOJ] 예산
4 participants