- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# C++ code to find the number of refill packs to be bought

Suppose, there are 'a' number of matches and 'b' number of press conferences to be held in a stadium in a particular week. There are two cafeterias, one in the player dressing room and one in the press conference area. There are two soft drink dispensers in the cafeterias and they need to be filled at the start of the week. The dressing room cafeteria drink dispenser is used heavily, and it needs to be refilled after every 'c' games and the conference area cafeteria's dispenser needs to be refilled after every 'd' events. The stadium maintenance committee can order k drink refill packs at the beginning of each week, 'x' packs for the dressing room cafeteria, and 'y' packs for the conference room cafeteria where x + y <= k. Given the match schedule, we have to find out the values of x and y, and if more than k refill packs are needed, we print "Limit Exceeded".

So, if the input is like a = 8, b = 8, c = 4, d = 6, k = 9, then the output will be 2, 2.

## Steps

To solve this, we will follow these steps −

a := (c + a - 1) / c b := (d + b - 1) / d if a + b <= k, then: print(a, b) Otherwise, print("Limit Exceeded")

## Example

Let us see the following implementation to get better understanding −

#include <bits/stdc++.h> using namespace std; #define N 100 void solve(int a, int b, int c, int d, int k) { a = (c + a - 1) / c; b = (d + b - 1) / d; if(a + b <= k) cout<<a<<" "<<b<<"\n"; else cout<<"Limit Exceeded."<<"\n"; } int main() { int a = 8, b = 8, c = 4, d = 6, k = 9; solve(a, b, c, d, k); return 0; }

## Input

8, 8, 4, 6, 9

## Output

2 2

- Related Questions & Answers
- C++ code to count number of packs of sheets to be bought
- Program to find maximum number of package that can be bought by buyers in C++
- Maximum number of candies that can be bought in C
- C++ code to find out which number can be greater
- C++ code to find the number of scans needed to find an object
- C++ code to find out number of battery combos
- C++ code to count number of times stones can be given
- Find the number of boxes to be removed in C++
- C++ code to find the number of dial rotations to print a string
- C++ code to find total number of digits in special numbers
- C++ code to find number to disprove given prime hypothesis
- What function in MySQL can be used to get the number code of a specific character?
- 8085 code to convert binary number to ASCII code
- Maximum litres of water that can be bought with N Rupees in C++
- Program to find out the number of boxes to be put into the godown in Python