問題一覧 > 教育的問題

No.8009 Longest Range of Distinct Numbers (for Study Session)

レベル : / AI推定難易度 : 700 / 実行時間制限 : 1ケース 5.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 79
作問者 : yuki2006
お気に入りにしたユーザー ProblemId : 338 / 自分の提出
問題文最終更新日: 2026-10-23 08:15:00
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original

Problem Statement

You are given $N$ natural numbers.
From them, you extract the $R-L+1 $ natural numbers in the range from the $L$-th to the $R$-th. $(1 \le L\le R \le N)$

If you choose $L$ and $R$ appropriately so that no natural number appears more than once in that range, what is the maximum number of natural numbers you can extract?

Input

$N$
$A_1\ A_2\ \dots\ A_N$

All input values are integers.
$1 \le N \le 10^5=100000$
$1 \le A_k \le 10^6=1000000$

Output

Output the maximum number of natural numbers that can be extracted.
Print a newline at the end.

Sample

Sample 1
Input
5
1 2 3 1 2
Output
3

For example, extracting $1,2,3$ gives 3 numbers.

Sample 2
Input
5
1 2 3 4 5
Output
5

You can take all of the numbers.

Sample 3
Input
5
1 1 1 1 1
Output
1

All of the numbers are the same.

Sample 4
Input
6
3 8 3 10 7 3
Output
4

The 4 numbers 8 3 10 7 are the maximum.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。