# Find if neat arrangement of cups and shelves can be made

Given three different types of cups (a[]) and saucers (b[]), and n number of shelves, find if neat arrangement of cups and shelves can be made.

Arrangement of the cups and saucers will be neat if it follows the below rules:

- No shelf can contain both cups and saucers
- There can be no more than 5 cups in any shelf
- There can be no more than 10 saucers in any shelf

Examples:

Input : a[] = {3, 2, 6} b[] = {4, 8, 9} n = 10 Output : Yes Explanation : Total cups = 11, shelves required = 3 Total saucers = 21, shelves required = 3 Total required shelves = 3 + 3 = 6, which is less than given number of shelves n. So, output is Yes. Input : a[] = {4, 7, 4} b[] = {3, 9, 10} n = 2 Output : No

**Approach :** To arrange the cups and the saucers, find out the total number of cups and total number of saucers . Since, there cannot be more than 5 cups in the same shelf, therefore find out the maximum number of shelves required for cup by the formula and the maximum number of shelves required for saucers by using the formula . If sum of these two values is equal to or less than then the arrangement is possible

otherwise not.

Below is the implementation of above approach :

## C++

`// C++ code to find if neat ` `// arrangement of cups and ` `// shelves can be made ` `#include<bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to check arrangement ` `void` `canArrange(` `int` `a[], ` `int` `b[], ` `int` `n) ` `{ ` ` ` `int` `suma = 0, sumb = 0; ` ` ` ` ` `// Calculating total number ` ` ` `// of cups ` ` ` `for` `(` `int` `i = 0; i < 3; i++) ` ` ` `suma += a[i]; ` ` ` ` ` `// Calculating total number ` ` ` `// of saucers ` ` ` `for` `(` `int` `i = 0; i < 3; i++) ` ` ` `sumb += b[i]; ` ` ` ` ` `// Adding 5 and 10 so that if the ` ` ` `// total sum is less than 5 and ` ` ` `// 10 then we can get 1 as the ` ` ` `// answer and not 0 ` ` ` `int` `na = (suma + 5 - 1) / 5; ` ` ` `int` `nb = (sumb + 10 - 1) / 10; ` ` ` ` ` `if` `(na + nb <= n) ` ` ` `cout << ` `"Yes"` `; ` ` ` `else` ` ` `cout << ` `"No"` `; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `// Number of cups of each type ` ` ` `int` `a[] = {3, 2, 6}; ` ` ` ` ` `// Number of saucers of each type ` ` ` `int` `b[] = {4, 8, 9}; ` ` ` ` ` `// Number of shelves ` ` ` `int` `n = 10; ` ` ` ` ` `// Calling function ` ` ` `canArrange(a, b, n); ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java code to find if neat ` `// arrangement of cups and ` `// shelves can be made ` `import` `java.io.*; ` ` ` `class` `Gfg ` `{ ` ` ` `// Function to check arrangement ` ` ` `public` `static` `void` `canArrange(` `int` `a[], ` `int` `b[], ` ` ` `int` `n) ` ` ` `{ ` ` ` `int` `suma = ` `0` `, sumb = ` `0` `; ` ` ` ` ` `// Calculating total number ` ` ` `// of cups ` ` ` `for` `(` `int` `i = ` `0` `; i < ` `3` `; i++) ` ` ` `suma += a[i]; ` ` ` ` ` `// Calculating total number ` ` ` `// of saucers ` ` ` `for` `(` `int` `i = ` `0` `; i < ` `3` `; i++) ` ` ` `sumb += b[i]; ` ` ` ` ` `// Adding 5 and 10 so that if ` ` ` `// the total sum is less than ` ` ` `// 5 and 10 then we can get 1 ` ` ` `// as the answer and not 0 ` ` ` `int` `na = (suma + ` `5` `- ` `1` `) / ` `5` `; ` ` ` `int` `nb = (sumb + ` `10` `- ` `1` `) / ` `10` `; ` ` ` ` ` `if` `(na + nb <= n) ` ` ` `System.out.println(` `"Yes"` `); ` ` ` `else` ` ` `System.out.println(` `"No"` `); ` ` ` `} ` ` ` ` ` `// Driver function ` ` ` `public` `static` `void` `main(String args[]) ` ` ` `{ ` ` ` `// Number of cups of each type ` ` ` `int` `a[] = {` `3` `, ` `2` `, ` `6` `}; ` ` ` ` ` `// Number of saucers of each type ` ` ` `int` `b[] = {` `4` `, ` `8` `, ` `9` `}; ` ` ` ` ` `// Number of shelves ` ` ` `int` `n = ` `10` `; ` ` ` ` ` `// Calling function ` ` ` `canArrange(a, b, n); ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

## Python 3

`# Python code to find if neat ` `# arrangement of cups and ` `# shelves can be made ` ` ` `import` `math ` ` ` `# Function to check arrangement ` `def` `canArrange( a, b, n): ` ` ` `suma ` `=` `0` ` ` `sumb ` `=` `0` ` ` ` ` `# Calculating total number ` ` ` `# of cups ` ` ` `for` `i ` `in` `range` `(` `0` `, ` `len` `(a)): ` ` ` `suma ` `+` `=` `a[i] ` ` ` ` ` `# Calculating total number ` ` ` `# of saucers ` ` ` `for` `i ` `in` `range` `(` `0` `,` `len` `(b)): ` ` ` `sumb ` `+` `=` `b[i] ` ` ` ` ` `# Adding 5 and 10 so that if ` ` ` `# the total sum is less than ` ` ` `# 5 and 10 then we can get 1 ` ` ` `# as the answer and not 0 ` ` ` `na ` `=` `(suma ` `+` `5` `-` `1` `) ` `/` `5` ` ` `nb ` `=` `(sumb ` `+` `10` `-` `1` `) ` `/` `10` ` ` ` ` `if` `(na ` `+` `nb <` `=` `n): ` ` ` `print` `(` `"Yes"` `) ` ` ` `else` `: ` ` ` `print` `(` `"No"` `) ` ` ` `# driver function ` ` ` `#Number of cups of each type ` `a ` `=` `[` `3` `, ` `2` `, ` `6` `] ` ` ` `# Number of saucers of each type ` `b ` `=` `[` `4` `, ` `8` `, ` `9` `] ` ` ` `# Number of shelves ` `n ` `=` `10` ` ` `#Calling function ` `canArrange(a ,b ,n) ` ` ` ` ` `# This code is contributed by Gitanjali. ` |

*chevron_right*

*filter_none*

## C#

`// C# code to find if neat ` `// arrangement of cups and ` `// shelves can be made ` `using` `System; ` ` ` `class` `Gfg { ` ` ` ` ` `// Function to check arrangement ` ` ` `public` `static` `void` `canArrange(` `int` `[]a, ` `int` `[]b, ` ` ` `int` `n) ` ` ` `{ ` ` ` ` ` `int` `suma = 0, sumb = 0; ` ` ` ` ` `// Calculating total number ` ` ` `// of cups ` ` ` `for` `(` `int` `i = 0; i < 3; i++) ` ` ` `suma += a[i]; ` ` ` ` ` `// Calculating total number ` ` ` `// of saucers ` ` ` `for` `(` `int` `i = 0; i < 3; i++) ` ` ` `sumb += b[i]; ` ` ` ` ` `// Adding 5 and 10 so that if ` ` ` `// the total sum is less than ` ` ` `// 5 and 10 then we can get 1 ` ` ` `// as the answer and not 0 ` ` ` `int` `na = (suma + 5 - 1) / 5; ` ` ` `int` `nb = (sumb + 10 - 1) / 10; ` ` ` ` ` `if` `(na + nb <= n) ` ` ` `Console.WriteLine(` `"Yes"` `); ` ` ` `else` ` ` `Console.WriteLine(` `"No"` `); ` ` ` `} ` ` ` ` ` `// Driver function ` ` ` `public` `static` `void` `Main() ` ` ` `{ ` ` ` ` ` `// Number of cups of each type ` ` ` `int` `[]a = {3, 2, 6}; ` ` ` ` ` `// Number of saucers of each type ` ` ` `int` `[]b = {4, 8, 9}; ` ` ` ` ` `// Number of shelves ` ` ` `int` `n = 10; ` ` ` ` ` `// Calling function ` ` ` `canArrange(a, b, n); ` ` ` `} ` `} ` ` ` `// This code is contributed by vt_m. ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP code to find if neat ` `// arrangement of cups and ` `// shelves can be made ` ` ` ` ` `// Function to check arrangement ` `function` `canArrange(` `$a` `, ` `$b` `, ` `$n` `) ` `{ ` ` ` `$suma` `= 0; ` `$sumb` `= 0; ` ` ` ` ` `// Calculating total number ` ` ` `// of cups ` ` ` `for` `( ` `$i` `= 0; ` `$i` `< 3; ` `$i` `++) ` ` ` `$suma` `+= ` `$a` `[` `$i` `]; ` ` ` ` ` `// Calculating total number ` ` ` `// of saucers ` ` ` `for` `( ` `$i` `= 0; ` `$i` `< 3; ` `$i` `++) ` ` ` `$sumb` `+= ` `$b` `[` `$i` `]; ` ` ` ` ` `// Adding 5 and 10 so that if the ` ` ` `// total sum is less than 5 and ` ` ` `// 10 then we can get 1 as the ` ` ` `// answer and not 0 ` ` ` `$na` `= (` `$suma` `+ 5 - 1) / 5; ` ` ` `$nb` `= (` `$sumb` `+ 10 - 1) / 10; ` ` ` ` ` `if` `(` `$na` `+ ` `$nb` `<= ` `$n` `) ` ` ` `echo` `"Yes"` `; ` ` ` `else` ` ` `echo` `"No"` `; ` `} ` ` ` ` ` `// Driver code ` ` ` ` ` `// Number of cups of each type ` ` ` `$a` `= ` `array` `(3, 2, 6); ` ` ` ` ` `// Number of saucers of each type ` ` ` `$b` `= ` `array` `(4, 8, 9); ` ` ` ` ` `// Number of shelves ` ` ` `$n` `= 10; ` ` ` ` ` `// Calling function ` ` ` `canArrange(` `$a` `, ` `$b` `, ` `$n` `); ` ` ` `// This code is contributed by vt_m. ` `?> ` |

*chevron_right*

*filter_none*

Output:

Yes

## Recommended Posts:

- Find the arrangement of queue at given time
- Find the longest string that can be made up of other strings from the array
- Program to print an array in Pendulum Arrangement
- Maximum height of triangular arrangement of array values
- Program to print an array in Pendulum Arrangement with constant space
- Check if array sum can be made K by three operations on it
- Count of numbers which can be made power of 2 by given operation
- Change if all bits can be made same by single flip
- Maximum elements that can be made equal with k updates
- Check if all elements of binary array can be made 1
- Finding n-th number made of prime digits (2, 3, 5 and 7) only
- Check if all the elements can be made equal on dividing with X and Y
- N-th character in the string made by concatenating natural numbers
- Minimum Cuts can be made in the Chessboard such that it is not divided into 2 parts
- Check whether an array can be made strictly decreasing by modifying at most one element

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.