2769. Find the Maximum Achievable Number
Given two integers,
numandt. A numberxis achievable if it can become equal tonumafter applying the following operation at mostttimes:
- Increase or decrease
xby1, and simultaneously increase or decreasenumby1.Return the maximum possible value of
x.Example 1:
Input: num = 4, t = 1
Output: 6
Explanation:
Apply the following operation once to make the maximum achievable number equal to
num:
- Decrease the maximum achievable number by 1, and increase
numby 1.Example 2:
Input: num = 3, t = 2
Output: 7
Explanation:
Apply the following operation twice to make the maximum achievable number equal to
num:
- Decrease the maximum achievable number by 1, and increase
numby 1.
def theMaximumAchievableX(self, num: int, t: int) -> int:
for i in range(t):
num += 2
return num