[HackerRank][Python3] Making Candies
2018. 7. 18. 01:50 |
프로그래밍/HackerRank
Problem :
https://www.hackerrank.com/challenges/making-candies/problem
My Solution :
#!/usr/bin/env python3
def check_possible(machine, worker, price, target, rounds):
if machine * worker >= target:
return True
rounds -= 1
curr_candy = machine * worker
while True:
remain = target - curr_candy
repeat = (remain + machine*worker - 1) // (machine * worker)
if repeat <= rounds:
return True
if curr_candy < price:
remain = price - curr_candy
repeat = (remain + machine * worker - 1) // (machine * worker)
rounds -= repeat
if rounds < 1:
return False
curr_candy += repeat * machine * worker
curr_candy -= price
if machine > worker:
worker += 1
else:
machine += 1
def minimumPasses(m, w, p, n):
low, high = 1, 10**12
while low < high:
mid = (low + high) // 2
if check_possible(m, w, p, n, mid):
high = mid
else:
low = mid + 1
return high
m, w, p, n = map(int, input().split())
result = minimumPasses(m, w, p, n)
print(result)
'프로그래밍 > HackerRank' 카테고리의 다른 글
| [HackerRank][Python3] Balanced Brackets (0) | 2018.07.20 |
|---|---|
| [HackerRank][Python3] Queues: A Tale of Two Stacks (0) | 2018.07.19 |
| [HackerRank][Python3] Abbreviation (0) | 2018.07.18 |
| [HackerRank][Python3] Max Array Sum (0) | 2018.07.18 |
| [HackerRank][Python3] Minimum Time Required (0) | 2018.07.17 |
| [HackerRank][Python3] Pairs (0) | 2018.07.17 |
| [HackerRank][Python3] Hash Tables: Ice Cream Parlor (0) | 2018.07.16 |
| [HackerRank][Python3] Triple sum (0) | 2018.07.16 |
최근에 달린 댓글 최근에 달린 댓글