Class Solution
- java.lang.Object
-
- g2701_2800.s2769_find_the_maximum_achievable_number.Solution
-
public class Solution extends Object
2769 - Find the Maximum Achievable Number.Easy
You are given two integers,
numandt.An integer
xis called achievable if it can become equal tonumafter applying the following operation no more thanttimes:- Increase or decrease
xby1, and simultaneously increase or decreasenumby1.
Return the maximum possible achievable number. It can be proven that there exists at least one achievable number.
Example 1:
Input: num = 4, t = 1
Output: 6
Explanation:
The maximum achievable number is x = 6; it can become equal to num after performing this operation:
1- Decrease x by 1, and increase num by 1. Now, x = 5 and num = 5.
It can be proven that there is no achievable number larger than 6.
Example 2:
Input: num = 3, t = 2
Output: 7
Explanation:
The maximum achievable number is x = 7; after performing these operations, x will equal num:
1- Decrease x by 1, and increase num by 1. Now, x = 6 and num = 4.
2- Decrease x by 1, and increase num by 1. Now, x = 5 and num = 5.
It can be proven that there is no achievable number larger than 7.
Constraints:
1 <= num, t <= 50
- Increase or decrease
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description inttheMaximumAchievableX(int num, int t)
-