Handshakes
Time limit2sMemory limit512 MB
Given each employee's handshake count with earlier arrivals, find the largest possible number of friends any single employee can have.
- Level
Medium7 of 10
- Topics
- Greedy, Graph, Array, Implementation
- Solved
- No attempts yet
Problem
A large company employs people. The employees are numbered with consecutive integers from to in the order they arrive at work each day. No two employees arrive at the same time, so employee arrives first, employee arrives second, and so on.
Some pairs of employees are friends, and friendship is symmetric: if employee considers employee a friend, then employee also considers employee a friend. When an employee arrives at work, he quickly walks around the office and shakes hands with all of his friends who are already in the office, that is, those who arrived before him. It is not known which pairs of employees are friends, but for each employee the number of handshakes he makes each day right after arriving at work is known.
The director of the company wants to talk with one of the employees about the current state of affairs. For this he wants to choose the most socially active person, namely the employee with the most friends. Using the available information, determine the maximum number of friends that one of the employees can have.
Input
The first line of the input contains a single number (), the number of employees in the company.
The second line of the input contains integers (). The -th number is the number of handshakes that employee made right after arriving at work, that is, before employee arrived.
Output
Print a single number: the maximum possible number of friends of one of the company's employees.
Notes
In the first example there is only one pair of employees, and they are friends, as follows from .
In the second example, if employees , , and all shook hands with the same employee, then that employee has friends.