問題一覧 > 通常問題

No.1438 Broken Drawers

レベル : / AI推定難易度 : 975 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 172
作問者 : first_vil / テスター : maspy
お気に入りにしたユーザー ProblemId : 4726 / 自分の提出
問題文最終更新日: 2021-03-20 23:45:06
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
yukicoder contest 288 (順位表) の他の問題:

Problem Statement

Vil has a broken chest of drawers at home. Once any drawer of this chest has been pulled out, it cannot be pushed back in, so it becomes impossible to take anything out of the drawer one level below the pulled-out drawer (this does not apply if the pulled-out drawer is the bottom one).

The chest consists of $N$ drawers in total, numbered in order from the bottom, and the $i$-th drawer contains the integer $A_i$ (all $A_i$ are distinct). Consider taking integers out of drawers $B_1,B_2,\dots,B_M$ of this chest in this order and arranging them in the order they were taken out to form a monotonically increasing sequence of length $M$. Here, the following condition must be satisfied.

  • For $B$ in the problem statement, there is no $(i,j)(i < j)$ satisfying $B_i-1=B_j$.

Find the length of the longest monotonically increasing sequence satisfying the above condition.

Input

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

  • All inputs are integers.
  • $1 \le N \le 2 \times 10^5$
  • $1 \le A_i \le N$
  • $A_i \neq A_j$ if $i \neq j$

Output

Output the length of the longest monotonically increasing sequence satisfying the condition in the problem statement, followed by a newline.

Sample

Sample 1
Input
5
2 3 4 1 5
Output
4

There are $2$ longest monotonically increasing sequences satisfying the condition: $(1,2,3,5),(2,3,4,5)$.

It is impossible to make $(1,2,3,4,5)$. This is because, if $B$ in the problem statement is defined for this monotonically increasing sequence, then $B_1-1=4-1=3=B_4$, which does not satisfy the condition.

Sample 2
Input
8
4 3 5 1 7 6 2 8
Output
5
Sample 3
Input
15
12 5 15 3 11 8 14 13 6 10 9 7 4 2 1
Output
8

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