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

[2023-08-28] sumin #145 #169

Merged
merged 1 commit into from
Aug 29, 2023
Merged

[2023-08-28] sumin #145 #169

merged 1 commit into from
Aug 29, 2023

Conversation

ksumini
Copy link
Contributor

@ksumini ksumini commented Aug 27, 2023

PR Summary

풀이시간: 20분

<input>

  • works: 길이 1 이상, 20,000 이하인 배열
  • works의 원소는 50000 이하인 자연수
  • n: 1,000,000 이하인 자연수

<solution>
a^2 + b^2 + ... + x^2이 최소가 되려면 계속해서 가장 작업량이 큰 수를 먼저 처리해야 함
예를 들어, [7, 8] 작업이 있다고 생각했을 때 당연하게도 8을 7로 줄이는 것이 야근 피로도가 최소가 되고 [7, 7]일 때는 어떤 것을 줄이든 상관없음. [7, 6]이 됐을 때는 다시 7을 6으로 줄이는 것이 야근 피로도를 최소화할 수 있게 됨
-> 이를 통해 항상 전체 작업 중 작업량이 가장 큰 값을 먼저 처리해야 됨을 알 수 있음
-> works의 길이가 최대 20,000이기 때문에 n번 max함수를 쓰면 시간초과가 나기 때문에 우선순위큐를 사용해서 최대값을 찾을 수 있음

<시간복잡도>
O(n): 최대 퇴근까지 남은 시간 n번만 확인하면 됨

@ksumini ksumini requested a review from limstonestone August 27, 2023 16:48
@ksumini ksumini self-assigned this Aug 27, 2023
- n: 1,000,000 이하인 자연수

<solution>
a^2 + b^2 + ... + x^2이 최소가 되려면 계속해서 가장 작업량이 큰 수를 먼저 처리해야 함
Copy link
Member

Choose a reason for hiding this comment

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

저도 다음의 아이디어에서 항상 어떻게 최대값을 가져오지 했는데 Heap이 있었네요! 안다고 생각했던 것들을 적절하게 사용하는 것도 체크가 필요할 것 같네요! 많은 걸 배워갑니다 ㅎㅎ

@Woo-Yeol Woo-Yeol linked an issue Aug 28, 2023 that may be closed by this pull request
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.

힙을 공부해보겠습니다...ㅎ
풀이 감사합니다 수밍님~!


<solution>
a^2 + b^2 + ... + x^2이 최소가 되려면 계속해서 가장 작업량이 큰 수를 먼저 처리해야 함
예를 들어, [7, 8] 작업이 있다고 생각했을 때 당연하게도 8을 7로 줄이는 것이 야근 피로도가 최소가 되고
Copy link
Contributor

Choose a reason for hiding this comment

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

아이디어를 떠올리기까지 과정을 간략하게 적어주신 점이 좋은 것 같아요!

O(n): 최대 퇴근까지 남은 시간 n번만 확인하면 됨

"""
import heapq
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 3337707 into main Aug 29, 2023
@ksumini ksumini deleted the sumin-#145 branch August 29, 2023 06:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Programmers] 야근 지수
4 participants