# Maximum no. of apples that can be kept in a single basket

Given the **‘N’** number of Basket and the total of Green **‘G’** and Red **‘R’** apples. The task is to distribute all the apples in the Basket and tell the maximum number of apples that can be kept in a basket.

**Note:** None of the basket is empty.

**Examples:**

Input:N = 2, R = 1, G = 1Output:Maximum apple kept is = 1Input:N = 2, R = 1, G = 2Output:Maximum apple kept is = 2

**Approach:** The idea is to just check the difference between no. of baskets and total no. of apples(red and Green) i.e. first put 1 apple in 1 basket that means the remaining apples will be extra and can be put together in any basket to make the count maximum. As there is already 1 apple in the basket. So, the maximum number of apples will be **(No_of_apples – No_of_baskets) + 1**. Since it is mentioned that none of the baskets is empty so apples will always be equal to or greater than no. of baskets.

Below is the implementation of the above approach:

## C++

`// C++ implementation of above approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function that will calculate the probability ` `int` `Number(` `int` `Basket, ` `int` `Red, ` `int` `Green) ` `{ ` ` ` `return` `(Green + Red) - Basket + 1; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `Basket = 3, Red = 5, Green = 3; ` ` ` ` ` `cout << ` `"Maximum apple kept is = "` ` ` `<< Number(Basket, Red, Green); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of above approach ` ` ` `import` `java.io.*; ` ` ` `class` `GFG { ` ` ` `// Function that will calculate the probability ` `static` `int` `Number(` `int` `Basket, ` `int` `Red, ` `int` `Green) ` `{ ` ` ` `return` `(Green + Red) - Basket + ` `1` `; ` `} ` ` ` `// Driver code ` ` ` `public` `static` `void` `main (String[] args) { ` ` ` ` ` `int` `Basket = ` `3` `, Red = ` `5` `, Green = ` `3` `; ` ` ` ` ` `System.out.println(` `"Maximum apple kept is = "` `+ ` ` ` `Number(Basket, Red, Green)); ` ` ` `} ` `//This Code is Contributed by akt_mit ` `} ` |

*chevron_right*

*filter_none*

## Python3

# Python 3 implementation of above approach

# Function that will calculate

# the probability

def Number(Basket, Red, Green):

return (Green + Red) – Basket + 1

# Driver code

if __name__ == ‘__main__’:

Basket = 3

Red = 5

Green = 3

print(“Maximum apple kept is =”,

Number(Basket, Red, Green))

# This code is contributed by

# Sanjit_Prasad

## C#

`//C# implementation of above approach ` ` ` `using` `System; ` ` ` `public` `class` `GFG{ ` ` ` `// Function that will calculate the probability ` `static` `int` `Number(` `int` `Basket, ` `int` `Red, ` `int` `Green) ` `{ ` ` ` `return` `(Green + Red) - Basket + 1; ` `} ` ` ` `// Driver code ` ` ` ` ` `static` `public` `void` `Main (){ ` ` ` `int` `Basket = 3, Red = 5, Green = 3; ` ` ` ` ` `Console.WriteLine(` `"Maximum apple kept is = "` `+ ` ` ` `Number(Basket, Red, Green)); ` ` ` `} ` `//This Code is Contributed by @ajit ` `} ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP implementation of above approach ` ` ` `// Function that will calculate ` `// the probability ` `function` `Number(` `$Basket` `, ` `$Red` `, ` `$Green` `) ` `{ ` ` ` `return` `(` `$Green` `+ ` `$Red` `) - ` `$Basket` `+ 1; ` `} ` ` ` `// Driver code ` `$Basket` `= 3; ` `$Red` `= 5 ; ` `$Green` `= 3; ` ` ` `echo` `"Maximum apple kept is = "` `, ` ` ` `Number(` `$Basket` `, ` `$Red` `, ` `$Green` `); ` ` ` `// This code is contributed by ANKITRAI1 ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

Maximum apple kept is = 6

## Recommended Posts:

- Maximum sum of distinct numbers such that LCM of these numbers is N
- Generate a pythagoras triplet from a single integer
- Python program maximum of three
- Program to find the minimum (or maximum) element of an array
- Find maximum and minimum distance between magnets
- Divide a number into two parts such that sum of digits is maximum
- Program to find the maximum element in a Matrix
- Maximum points of intersection n lines
- Find single Movement in a Matrix
- Maximum students to pass after giving bonus to everybody and not exceeding 100 marks
- Find maximum element of each column in a matrix
- Pick maximum sum M elements such that contiguous repetitions do not exceed K
- Check if the first and last digit of number N is prime and their sum is less than K
- Program to parse the Molecules and get the Atoms count

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.