Dr. Vishnu is opening a new world-class hospital in a small town designed to be the first preference of the patients in the city. Hospital has N rooms of two types with TV and without TV, with daily rates of R1 and R2 respectively. However, from his experience Dr. Vishnu knows that the number of patients is not constant throughout the year, instead, it follows a pattern. The number of patients on any given day of the year is given by the following formula:
Patients per day = (6 – M)2 + |D – 15|
M: the number of month starting from 1 to 12
D: the date from 1 to 31
All patients prefer without TV rooms as they are cheaper, but will opt for with TV rooms only if without TV rooms are not available. Hospital has a revenue target for the first year of operation. Given this target and the values of N, R1, and R2 you need to identify the number of TVs the hospital should buy so that it meets the revenue target. Assume the Hospital opens on 1st Jan and year is a non-leap year.
Input: N = 20, R1 = 1500, R2 = 1000, target = 7000000
Using the formula:
The number of patients on 1st Jan will be 39, on 2nd Jan will be 38 and so on.
Considering there are only twenty rooms and rates of both type of rooms are 1500 and 1000 respectively.
Therefore, 14 TV sets are needed to get the revenue of 7119500 with 13 TV sets.
The total revenue will be less than 7000000.
Input: N = 10, R1 = 1000, R2 = 1500, target = 10000000
In the above example, the target will not be achieved, even by equipping all the rooms with TV.
Hence, the answer is 10 i.e., total number of rooms in the hospital.
Approach: The idea is to traverse through the whole year and generate revenue for each day. Find the revenue for the first year for every possible number of rooms that can have a TV. Follow the below steps to solve the problem:
- Suppose the total number of rooms having a TV is tvs, where 0 ≤ tvs ≤ N.
- For each number for TVs, revenue for the first year can be found by traversing through each day.
- The above formula can be used to find the number of patients per day. Suppose np is the current number of patients.
- The current number of patients np can have the value of the number of patients today or the total number of rooms whichever is minimum.
- If the number of patients is less than the number of rooms without TV, then the total revenue for today will be np*R1 because it is cheap.
- Else if the number of patients is greater than the rooms without TV, then the total revenue for today is given by:
(N – tvs)*R2 + (np – (N – tvs))*R1
- Add the revenue for each day in target value and print the maximum target value generated after checking all possible combinations.
Below is the implementation of the above approach:
Time Complexity: O(N*365), where N is the given number of rooms.
Auxiliary Space: O(1)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Prime Fibonnaci | TCS Mockvita 2020
- Collision Course | TCS MockVita 2020
- Philaland Coin | TCS Mockvita 2020
- Cartesian Product of Two Sets
- Possible two sets from first N natural numbers difference of sums as D
- First N natural can be divided into two sets with given difference and co-prime sums
- Minimum number of sets with numbers less than Y
- Count of sub-sets of size n with total element sum divisible by 3
- Find the Jaccard Index and Jaccard Distance between the two given sets
- Number of K's such that the given array can be divided into two sets satisfying the given conditions
- Find sum of f(s) for all the chosen sets from the given array
- Split N natural numbers into two sets having GCD of their sums greater than 1
- Split an array containing N elements into K sets of distinct elements
- Print all distinct Coprime sets possible from 1 to N
- First element of every K sets having consecutive elements with exactly K prime factors less than N
- Split first N natural numbers into two sets with minimum absolute difference of their sums
- Split squares of first N natural numbers into two sets with minimum absolute difference of their sums
- TCS Interview experience through TCS Ninja
- TCS NQT Coding Questions & How Coding Task Evaluated in TCS NQT
- TCS Ninja Interview Experience CSE 2020
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.