From db1128ebba8ef63de68c1ed7f88560ce09676fa1 Mon Sep 17 00:00:00 2001 From: Anova07 <65520755+Anova07@users.noreply.github.com> Date: Fri, 15 Oct 2021 12:00:35 +0530 Subject: [PATCH 1/2] Create HalloweenSales.py --- HackerRank/HalloweenSales.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 HackerRank/HalloweenSales.py diff --git a/HackerRank/HalloweenSales.py b/HackerRank/HalloweenSales.py new file mode 100644 index 0000000..bd86cab --- /dev/null +++ b/HackerRank/HalloweenSales.py @@ -0,0 +1,34 @@ +import sys +import math + +def howManyGames(p, d, m, s): + t_l = 0 + if p % d != 0: + t_l = p % d + else: + t_l = d + d = -d + t_n = ((t_l-p)/d) + 1 + t_sum = (t_n*(p+t_l))/2 + if s > t_sum: + n = ((m-p)/d) + 1 + l = p+((n-1)*d) + sn = (n*(p+l))/2 + return n+((s-sn)/m) + else: + x1 = abs(int(((-((2*p)-d))+math.sqrt((((2*p)-d)**2)-((4*d)*(-(2*s)))))/(2*d))) + x2 = abs(int(((-((2*p)-d))-math.sqrt((((2*p)-d)**2)-((4*d)*(-(2*s)))))/(2*d))) + l = p+((x1-1)*d) + s1 = (x1*(p+l))/2 + l = p+((x2-1)*d) + s2 = (x2*(p+l))/2 + if s1 <= s: + return x1 + else: + return x2 + +if __name__ == "__main__": + p, d, m, s = raw_input().strip().split(' ') + p, d, m, s = [int(p), int(d), int(m), int(s)] + answer = howManyGames(p, d, m, s) + print answer From 3e28cd1d852e620ee1edbef0c3c4da739ef7fd9b Mon Sep 17 00:00:00 2001 From: Anova07 <65520755+Anova07@users.noreply.github.com> Date: Fri, 15 Oct 2021 12:02:19 +0530 Subject: [PATCH 2/2] Update HalloweenSales.py --- HackerRank/HalloweenSales.py | 1 + 1 file changed, 1 insertion(+) diff --git a/HackerRank/HalloweenSales.py b/HackerRank/HalloweenSales.py index bd86cab..565f9a5 100644 --- a/HackerRank/HalloweenSales.py +++ b/HackerRank/HalloweenSales.py @@ -15,6 +15,7 @@ def howManyGames(p, d, m, s): l = p+((n-1)*d) sn = (n*(p+l))/2 return n+((s-sn)/m) + else: x1 = abs(int(((-((2*p)-d))+math.sqrt((((2*p)-d)**2)-((4*d)*(-(2*s)))))/(2*d))) x2 = abs(int(((-((2*p)-d))-math.sqrt((((2*p)-d)**2)-((4*d)*(-(2*s)))))/(2*d)))