IBMOA #3
Find Max Team Size
Estimated EasyJudge-ready
Topics (AI-labelled)In-place ArraysHashing
Select as many students as possible such that, after sorting by skill, any two adjacent students differ by 0 or 1. The team may span several consecutive skill values; the team's maximum minus minimum is not required to be ≤1.
Input
The first line contains n, and the second line contains the skills. On this site 1≤n≤200000, −10^9≤skill≤10^9.
Output
Output one integer, the answer.
Example 1
Input:
5
10 12 13 9 14
Output:
3
Example 2
Input:
4
1 2 3 4
Output:
4
Example 3
Input:
3
5 5 7
Output:
2
Example notes
The examples give 3, 4 and 2 respectively. The source editorial only counts two adjacent values, which conflicts with the statement body and the first example; this site corrects it according to the body.
Editorial
Loading solution…