PY
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
'''
Given:
- The party starts at 8 PM and ends at midnight (12 AM), which is a total of 4 hours.
- Max needs to travel to the party venue, which takes him P minutes.
- It takes Max 5*i minutes to solve the i-th problem.
Total time to solve problems = 4 hours (240 minutes) - P minutes
Next, we need to calculate how many problems Max can solve within the remaining time frame:
The time required to solve X problems = 5*1 + 5*2 + ... + 5*X = 5*(1+2+...+X) = 5*X*(X+1)/2
So, we solve the following inequality:
5*X*(X+1)/2 <= total time to solve problems
Now, solve for X:
5*X*(X+1)/2 <= 240 - P
5*X*(X+1) <= 480 - 2*P
X*(X+1) <= (480 - 2*P)/5
The valid solutions for X are the integer values that satisfy the inequality above.
Finally, return the maximum integer value of X that satisfies the inequality as the number of problems Max can solve and still reach the party venue within the given time frame.
'''
# formula to solve
# x*(x+1)=(480-2*p)/5
import math
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run