Given three integers **N**, **X, **and **Y, **the task is to check if it is possible to reduce **N** to 0 or less by the following operations:

- Update
**N**to**⌊N/2⌋ + 10,**at most**X**times - Update
**N**to**N – 10,**at most**Y**times.

**Example:**

Input:N = 100, X = 3, Y = 4Output:YesExplanation:

Update N = 100 to ⌊100/2⌋ + 10 = 60.

Update N = 60 to 60 − 10 = 50.

Update N = 50 to ⌊50/2⌋ + 10 = 35.

Update N = 35 to ⌊35/2⌋ + 10 = 27.

Update N = 27 to 27 − 10 = 17.

Update N = 17 to 17 − 10 = 7.

Update N = 7 to 7 − 10 = −3.

Input:N = 50, X = 1, Y = 2Output:No

**Approach:** This problem can be solved based on the following observations:

**Case 1:**If**⌊N/2⌋ + 10 >= N**, then perform only second operation as the first operation will increase the value**N**.**Case 2:**If first operation is performed followed by the second operation then the result is:

Operation 1: N = ⌊N/2⌋ + 10

Operation 2: (⌊N/2⌋ + 10) – 10 = ⌊N/2⌋The value of

**N**is reduced to**(⌊N/2⌋)**.**Case 3:**If second operation is performed followed by the first operation then the result is:

Operation 2: N = N – 10

Operation 1: ⌊(N – 10)/2⌋ + 10 = (⌊N/2⌋ – 5 + 10) = (⌊N/2⌋ + 5)The value of

**N**is reduced to**(⌊N/2⌋ + 5)**.

From the above two observations, if **N > N/2 +10**, then it can be concluded that, to reduce the value of **N** to** 0** or less, the first operation must be performed before the second operation to decrease the value of **N**.

Follow the steps below to solve the problem:

- Update the value of
**N**to**⌊N/2⌋ + 10**if N > N/2 + 10 and X > 0. - Update the value of
**N**to**N – 10**at most Y times. - Check if the updated value of
**N**is less than equal to 0 or not. - If N ≤ 0, then print
**“Yes”**. Otherwise, print**“No”**.

Below is the implementation of the above approach:

## C++

`// C++ Program to implement ` `// the above approach ` ` ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to check if N can be ` `// reduced to <= 0 or not ` `bool` `NegEqu(` `int` `N, ` `int` `X, ` `int` `Y) ` `{ ` ` ` ` ` `// Update N to N/2 + 10 at most X times ` ` ` `while` `(X-- and N > N/2 + 10) { ` ` ` `N = N / 2 + 10; ` ` ` `} ` ` ` ` ` `// Update N to N - 10 Y times ` ` ` `while` `(Y--) { ` ` ` `N = N - 10; ` ` ` `} ` ` ` ` ` `if` `(N <= 0) ` ` ` `return` `true` `; ` ` ` ` ` `return` `false` `; ` `} ` ` ` `// Driver Code ` `int` `main() ` `{ ` ` ` `int` `N = 100; ` ` ` `int` `X = 3; ` ` ` `int` `Y = 4; ` ` ` ` ` `if` `(NegEqu(N, X, Y)) { ` ` ` `cout << ` `"Yes"` `; ` ` ` `} ` ` ` `else` `{ ` ` ` `cout << ` `"No"` `; ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to implement ` `// the above approach ` `class` `GFG{ ` ` ` `// Function to check if N can be ` `// reduced to <= 0 or not ` `static` `boolean` `NegEqu(` `int` `N, ` `int` `X, ` `int` `Y) ` `{ ` ` ` ` ` `// Update N to N/2 + 10 at most X times ` ` ` `while` `(X > ` `0` `&& (N > N / ` `2` `+ ` `10` `)) ` ` ` `{ ` ` ` `N = N / ` `2` `+ ` `10` `; ` ` ` `X -= ` `1` `; ` ` ` `} ` ` ` ` ` `// Update N to N - 10 Y times ` ` ` `while` `(Y > ` `0` `) ` ` ` `{ ` ` ` `N = N - ` `10` `; ` ` ` `Y -= ` `1` `; ` ` ` `} ` ` ` ` ` `if` `(N <= ` `0` `) ` ` ` `return` `true` `; ` ` ` ` ` `return` `false` `; ` `} ` ` ` `// Driver Code ` `public` `static` `void` `main(String[] args) ` `{ ` ` ` `int` `N = ` `100` `; ` ` ` `int` `X = ` `3` `; ` ` ` `int` `Y = ` `4` `; ` ` ` ` ` `if` `(NegEqu(N, X, Y)) ` ` ` `{ ` ` ` `System.out.println(` `"Yes"` `); ` ` ` `} ` ` ` `else` ` ` `{ ` ` ` `System.out.println(` `"No"` `); ` ` ` `} ` `} ` `} ` ` ` `// This code is contributed by jana_sayantan ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program to implement ` `# the above approach ` ` ` `# Function to check if N can be ` `# reduced to <= 0 or not ` `def` `NegEqu(N, X, Y): ` ` ` ` ` `# Update N to N/2 + 10 at most X times ` ` ` `while` `(X ` `and` `N > N ` `/` `/` `2` `+` `10` `): ` ` ` `N ` `=` `N ` `/` `/` `2` `+` `10` ` ` `X ` `-` `=` `1` ` ` ` ` `# Update N to N - 10 Y times ` ` ` `while` `(Y): ` ` ` `N ` `=` `N ` `-` `10` ` ` `Y ` `-` `=` `1` ` ` ` ` `if` `(N <` `=` `0` `): ` ` ` `return` `True` ` ` ` ` `return` `False` ` ` `# Driver Code ` `if` `__name__ ` `=` `=` `'__main__'` `: ` ` ` ` ` `N ` `=` `100` ` ` `X ` `=` `3` ` ` `Y ` `=` `4` ` ` ` ` `if` `(NegEqu(N, X, Y)): ` ` ` `print` `(` `"Yes"` `) ` ` ` `else` `: ` ` ` `print` `(` `"No"` `) ` ` ` `# This code is contributed by mohit kumar 29 ` |

*chevron_right*

*filter_none*

## C#

`// C# program to implement ` `// the above approach ` `using` `System; ` ` ` `class` `GFG{ ` ` ` `// Function to check if N can be ` `// reduced to <= 0 or not ` `public` `static` `bool` `NegEqu(` `int` `N, ` `int` `X, ` ` ` `int` `Y) ` `{ ` ` ` ` ` `// Update N to N/2 + 10 at most X times ` ` ` `while` `(X > 0 && (N > N / 2 + 10)) ` ` ` `{ ` ` ` `N = N / 2 + 10; ` ` ` `X -= 1; ` ` ` `} ` ` ` ` ` `// Update N to N - 10 Y times ` ` ` `while` `(Y > 0) ` ` ` `{ ` ` ` `N = N - 10; ` ` ` `Y -= 1; ` ` ` `} ` ` ` ` ` `if` `(N <= 0) ` ` ` `return` `true` `; ` ` ` ` ` `return` `false` `; ` `} ` ` ` `// Driver Code ` `public` `static` `void` `Main(String[] args) ` `{ ` ` ` `int` `N = 100; ` ` ` `int` `X = 3; ` ` ` `int` `Y = 4; ` ` ` ` ` `if` `(NegEqu(N, X, Y)) ` ` ` `{ ` ` ` `Console.WriteLine(` `"Yes"` `); ` ` ` `} ` ` ` `else` ` ` `{ ` ` ` `Console.WriteLine(` `"No"` `); ` ` ` `} ` `} ` `} ` ` ` `// This code is contributed by jana_sayantan ` |

*chevron_right*

*filter_none*

**Output:**

Yes

** Time Complexity: **O(X + Y)

**Auxiliary Space**:O(1)

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Reduce a given number to form a key by the given operations
- Count operations of the given type required to reduce N to 0
- Count the number of operations required to reduce the given number
- Minimum number of given operations required to reduce the array to 0 element
- Reduce N to 1 with minimum number of given operations
- Reduce a number to 1 by performing given operations | Set 2
- Minimum steps to reduce N to 0 by given operations
- Minimum number of operations required to reduce N to 1
- Find maximum operations to reduce N to 1
- Min number of operations to reduce N to 0 by subtracting any digits from N
- Min operations to reduce N to 1 by multiplying by A or dividing by B
- Min operations to reduce N by multiplying by any number or taking square root
- Minimum number of operations required to reduce N to 0
- Reduce the array to a single element with the given operation
- Reduce given three Numbers by decrementing in Pairs
- Minimum cost to reduce the integer N to 1 as per given conditions
- Reduce a given Binary Array to a single element by removal of Triplets
- Minimum replacement of pairs by their LCM required to reduce given array to its LCM
- Steps to reduce N to zero by subtracting its most significant digit at every step
- Reduce the fraction to its lowest form

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.