A concert is organized in an auditorium with capacity \(C\). They have opened a booking system where fans can buy tickets by giving their group size, entry time and exit time. The organizers want to accommodate all the groups in order to maximize profit. All this information is stored in a 2D array \(audience\), where \(audience[i] = [strength, entry \: time, exit \: time]\).
Task
Check if all the groups can be accommodated in the auditorium.
Notes
- The entry time and exit times are inclusive.
- All people enter after the start of the concert and leave before the end of the concert.
Example 1
Assumptions
Input
- N = 2
- C = 5
- audience = [[2, 1, 5], [3, 3, 7]]
Output: Yes
Approach
- At time 1, 2 people enter. At time 3, 3 more people enter. The total number of people is 5.
- At time 5, 2 people exit, and the total number of people is 3. At time 7, 3 people exit.
Function description
Complete the function solution() provided in the editor. The function takes 3 parameters and returns the solution:
- N: Represents the number of groups
- C: Represents the capacity of the auditorium
- audience: Represents the strength, entry time, and exit time of each group
Input format
Note: This is the input format that you must use to provide custom input (available above the Compile and Test button).
- The first line contains N denoting the number of initial chocolates in Alex’s box.
- The second line contains C denoting the number of initial chocolates in Drake’s box.
- Each of the next N lines contains three integers, the ith line of which indicates the strength, entry time, and exit time of ith group.
Output format
Print a string representing if it is possible to accommodate all groups.
Constraints
Sample
Given
Input
- N = 2
- C = 4
- audience = [[2, 1, 5], [3, 3, 7]]
Output: No
Approach
At time 1, 2 people enter. At time 3, 3 more people enter. The total number of people is 5. This exceeds the capacity, hence the answer is No.
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor