Cinema Invitation
InterviewTime limit1sMemory limit128 MB
Given each friend's minimum required number of other attending friends, find the smallest subset size satisfying everyone invited's threshold.
- Level
Medium5 of 10
- Topics
- Greedy, Sorting, Binary search
- Solved
- No attempts yet
Problem
Mirko wants to invite some friends to the cinema for his birthday.
His friends like going to the cinema in large groups. Friend i will go only if, besides Mirko and that friend, at least Zi other friends also go.
Mirko cannot afford to invite everyone, so he wants to invite as few friends as possible. Find the minimum positive number of friends he can invite so that every invited friend's request is satisfied.
Input
The first line contains an integer N, the number of friends. (2 ≤ N ≤ 10 000)
Each of the next N lines contains one integer Zi. (1 ≤ Zi < N) This value is the minimum number of other friends that friend i requires in order to go to the cinema.
Output
Print the minimum number of friends Mirko can invite to the cinema.