- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find if neat arrangement of cups and shelves can be made in Python
Suppose we have three different types of cups in array p and saucers in array q and m number of shelves, we have to check whether a neat arrangement of cups and shelves can be made.
We can say that arrangement of the cups and saucers will be neat if it follows these conditions − 1. No shelf can hold both cups and saucers. 2. A self may contain at most 5 cups. 3. A self may contain at most 10 saucers.
So, if the input is like p = [4, 3, 7] q = [5, 9, 10] m = 11, then the output will be True as total number of cups = 14, 3 shelves are required, total saucers = 24, 3 shelves are required. So, total required shelves = 3 + 3 = 6, which is smaller than given number of shelves m.
To solve this, we will follow these steps −
sum_p := 0, sum_q := 0
for i in range 0 to size of p, do
sum_p := sum_p + p[i]
for i in range 0 to size of q, do
sum_q := sum_q + q[i]
m_p :=(sum_p + 4) / 5
m_q :=(sum_q + 9) / 10
if m_p + m_q <= m, then
Let us see the following implementation to get better understanding −
def is_valid(p, q, m): sum_p = 0 sum_q = 0 for i in range(0, len(p)): sum_p += p[i] for i in range(0,len(q)): sum_q += q[i] m_p = (sum_p + 5 - 1) / 5 m_q = (sum_q + 10 - 1) / 10 if(m_p + m_q <= m): return True else: return False p = [4, 3, 7] q = [5, 9, 10] m = 11 print(is_valid(p ,q ,m))
[4, 3, 7], [5, 9, 10], 11
- Find if neat arrangement of cups and shelves can be made in C++
- Is pizza healthy? If not, can it be made healthy?
- Check if elements of array can be made equal by multiplying given prime numbers in Python
- Check if a two-character string can be made using given words in Python
- Check if array sum can be made K by three operations on it in Python
- C++ Program to find out if a palindromic matrix can be made from a given matrix
- Program to find the length of the longest, that can be made using given letters in Python
- How can Indian prisons be made secure?
- Can a constructor be made final in Java?
- C++ program to find out the number of coordinate pairs that can be made
- Filling Bookcase Shelves in Python
- C++ code to count maximum groups can be made
- Program to count number of horizontal brick pattern can be made from set of bricks in Python
- Check whether the number can be made perfect square after adding 1 in Python