Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update main.py #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions src/Financial Planning/Python 3/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
def main():
n,m = map(int,input().split())
lis = sorted(((lambda a,b: (a,b,b//a+1))(*map(int,input().split())) for _ in range(n)),key=lambda z: (z[2],z[0],-z[1]))
# Read the input values n and m
n, m = map(int, input().split())

# Create a list of tuples containing information for each day: (d, c, days_needed)
# d: daily profit, c: cost, days_needed: days needed to complete the task
lis = sorted(
(
(
lambda a, b: (a, b, b // a + 1)
)(*map(int, input().split()))
for _ in range(n)
),
key=lambda z: (z[2], z[0], -z[1])
)

daily_profit = 0
cost = 0
Expand All @@ -9,16 +21,19 @@ def main():
day = lis[0][2]

while True:
# Calculate the total daily profit and cost for the current day
while _next < len(lis) and lis[_next][2] == day:
d,c,_ = lis[_next]
d, c, _ = lis[_next]
cost += c
daily_profit += d
_next += 1

if day*daily_profit - cost >= m:
# Check if the accumulated profit is enough to cover the target profit m
if day * daily_profit - cost >= m:
break
day += 1
print(day)

day += 1 # Increment the day
print(day) # Print the final day needed to achieve the target profit

if __name__ == "__main__":
main()
main()