MathWorksOA #16
Maximize Beauty
Estimated MediumJudge-ready
Topics (AI-labelled)Subsequences
The beauty of an array is the number of 1-based positions i with arr[i]=i. You may repeatedly delete any element, as long as the array keeps a length of at least 1, and the order does not change. Find the maximum possible beauty.
This site uses a standard input/output protocol.
Input
The first line contains n; the second line contains n positive integers. 1≤n≤2000, 1≤arr[i]≤10^5.
Output
Output the maximum beauty.
Example 1
Input:
7
1 3 2 5 4 5 3
Output:
4
Example 2
Input:
6
6 3 2 4 3 4
Output:
3
Example 3
Input:
1
7
Output:
0
Example 4
Input:
3
2 2 2
Output:
1
Editorial
Loading solution…