-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearch-Making Candies.py
54 lines (40 loc) · 1.06 KB
/
Search-Making Candies.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#Problem Link : https://www.hackerrank.com/challenges/making-candies/problem?isFullScreen=true&h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=search
#Ans:
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'minimumPasses' function below.
#
# The function is expected to return a LONG_INTEGER.
# The function accepts following parameters:
# 1. LONG_INTEGER m
# 2. LONG_INTEGER w
# 3. LONG_INTEGER p
# 4. LONG_INTEGER n
#
def main():
m, w, p, n = map(int, input().split())
answer = math.ceil(n / (m * w))
candies = 0
passed = 0
while True:
left = math.ceil((n - candies) / (m * w))
answer = min(answer, passed + left)
if left <= 1:
break
if candies < p:
required = math.ceil((p - candies) / (m * w))
passed += required
candies += required * m * w
if m < w:
m += 1
else:
w += 1
candies -= p
print(answer)
if __name__ == '__main__':
main()