mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 19:53:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			48 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			48 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>Given two integers, <code>num</code> and <code>t</code>. A <strong>number </strong><code>x</code><strong> </strong>is<strong> achievable</strong> if it can become equal to <code>num</code> after applying the following operation <strong>at most</strong> <code>t</code> times:</p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li>Increase or decrease <code>x</code> by <code>1</code>, and <em>simultaneously</em> increase or decrease <code>num</code> by <code>1</code>.</li>
 | 
						|
</ul>
 | 
						|
 | 
						|
<p>Return the <strong>maximum </strong>possible value of <code>x</code>.</p>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong class="example">Example 1:</strong></p>
 | 
						|
 | 
						|
<div class="example-block">
 | 
						|
<p><strong>Input:</strong> <span class="example-io">num = 4, t = 1</span></p>
 | 
						|
 | 
						|
<p><strong>Output:</strong> <span class="example-io">6</span></p>
 | 
						|
 | 
						|
<p><strong>Explanation:</strong></p>
 | 
						|
 | 
						|
<p>Apply the following operation once to make the maximum achievable number equal to <code>num</code>:</p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li>Decrease the maximum achievable number by 1, and increase <code>num</code> by 1.</li>
 | 
						|
</ul>
 | 
						|
</div>
 | 
						|
 | 
						|
<p><strong class="example">Example 2:</strong></p>
 | 
						|
 | 
						|
<div class="example-block">
 | 
						|
<p><strong>Input:</strong> <span class="example-io">num = 3, t = 2</span></p>
 | 
						|
 | 
						|
<p><strong>Output:</strong> <span class="example-io">7</span></p>
 | 
						|
 | 
						|
<p><strong>Explanation:</strong></p>
 | 
						|
 | 
						|
<p>Apply the following operation twice to make the maximum achievable number equal to <code>num</code>:</p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li>Decrease the maximum achievable number by 1, and increase <code>num</code> by 1.</li>
 | 
						|
</ul>
 | 
						|
</div>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong>Constraints:</strong></p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li><code>1 <= num, t <= 50</code></li>
 | 
						|
</ul>
 |