Take Me There

Computer Science Level 4

There are \(N\) men gathered outside of a cinema hoping to watch the newly released movie Star Wars. The \(i^\text{th}\) person will only go in if at least \(L_{i}\) other people will go with him because he doesn't want to get lonely. Additionally, that person doesn't want to go with more than \(H_{i}\) other people since it would get crowded and ruin the experience.

This text contains \(N\) spaced integers each representing the \((L_{i}, H_{i})\) of the \(i^\text{th}\) individual. What is the maximum number of men that can get inside at one time such that no constraint is violated?

Details and assumptions:

  • The first line indicates the number of people \(N\).
  • For example, the maximum number of people is 3 in the case below. Each of them can take another 2 people, but not anymore.
1 4
1 2
1 4
1 3

Problem Loading...

Note Loading...

Set Loading...