#P3287. [SCOI2014] 方伯伯的玉米田

    ID: 2336 远端评测题 3000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划,dp2014四川树状数组O2优化

[SCOI2014] 方伯伯的玉米田

Description

While walking along the edge of his farmland, Uncle Fang suddenly noticed that one row of corn looked very unattractive. There are NN stalks in this row, and their heights vary. Uncle Fang thinks a non-decreasing sequence is beautiful, so he decides to first raise some stalks and then pull out any stalks that spoil the beauty, so that the heights of the remaining stalks form a non-decreasing sequence. He may choose an interval and increase every stalk in that interval by 1 unit of height; he may perform at most KK such operations. He may also freely choose any set of stalks to remove. What is the maximum number of stalks that can remain to form a beautiful row?

Input Format

The first line contains two integers nn, KK, denoting the number of stalks in this row and the maximum number of operations allowed, respectively. The second line contains nn integers; the ii-th number is the height aia_i of the ii-th stalk from left to right.

Output Format

Output a single integer, the maximum number of remaining stalks.

3 1
2 1 3
3

Hint

Constraints: 100%100\% of the testdata satisfies: 2N<1042 \le N \lt 10^4 , 2K5002 \le K \le 500, 1ai50001 \leq a_i \leq 5000.

Translated by ChatGPT 5