Concert capacity

4.7

3 votes
Suffix Array, Advanced Data Structures, Real world, Data Structures
Problem

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,entrytime,exittime].

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

1N1051C1091strength1091entrytimeexittime109

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

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.

Editor Image

?