
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
C++ program to find maximum profit we can make by making hamburger and chicken burgers
Suppose we have five numbers b, p, f, h and c. There are two types of burgers in a restaurant. These are hamburger and chicken burger. Hamburger needs two buns and a beef patty and for chicken burger we need two buns and a chicken cutlet. We have b buns, p beef patties, f chicken cutlets. We are trying to sell hamburger for h rupees and chicken burger for c rupees. We have to find the maximum profit that we can gain.
So, if the input is like b = 7; p = 5; f = 2; h = 10; c = 12, then the output will be 34, because for one hamburgers and two chicken burgers. The income is 1*10 + 2*12 = 34.
Steps
To solve this, we will follow these steps −
res := 0 b := b / 2 if h < c, then: swap p and f swap h and c res := res + h * (minimum of b and p) + c * minimum of the (maximum of (b - p) and 0) and f) return res
Example
Let us see the following implementation to get better understanding −
#include <bits/stdc++.h> using namespace std; int solve(int b, int p, int f, int h, int c) { int res = 0; b /= 2; if (h < c) { swap(p, f); swap(h, c); } res += h * min(b, p) + c * min(max(b - p, 0), f); return res; } int main() { int b = 7; int p = 5; int f = 2; int h = 10; int c = 12; cout << solve(b, p, f, h, c) << endl; }
Input
7, 5, 2, 10, 12
Output
34
- Related Articles
- Program to find maximum profit we can make by holding and selling profit in Python
- Program to find maximum profit we can make by buying and selling stocks in Python?
- Program to find maximum profit we can make after k Buy and Sell in python
- Program to find maximum profit we can get by buying and selling stocks with a fee in Python?
- Program to find the maximum profit we can get by buying on stock market once in Python
- C++ code to get maximum profit by house making
- Program to find the maximum profit we can get by buying on stock market multiple times in Python
- Program to find maximum number of people we can make happy in Python
- Program to find maximum profit by selling diminishing-valued colored balls in Python
- Program to get maximum profit by scheduling jobs in Python
- Program to find maximum credit we can get by finishing some assignments in python
- Program to find maximum profit by cutting the rod of different length in C++
- Program to find possible number of palindromes we can make by trimming string in Python
- Program to find maximum price we can get by holding items into a bag in Python
- Program to find maximum number of consecutive values you can make in Python

Advertisements