QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB Total points: 100

#796. 全球变暖

Statistics

全球变暖是一个重要的问题,Johnny 对此有所了解。他决定分析历史气温,并找到一个气温严格递增的日期子序列(不一定连续)。这将说服那些怀疑论者!

Johnny 找到了 $n$ 个连续日期的历史数据。第 $i$ 天的气温为 $t_i$。

形式化地,我们感兴趣的是找到序列 $(t_1, t_2, \dots, t_n)$ 的最长递增子序列(LIS)的长度,即找到最大的 $k$,使得存在下标序列 $1 \le a_1 < a_2 < \dots < a_k \le n$,满足 $t_{a_1} < t_{a_2} < \dots < t_{a_k}$。

Johnny 想要找到一个非常长的子序列,这就是他决定稍微作弊的原因。他将首先选择一个非空的日期区间,以及一个整数 $d$($-x \le d \le x$),并将这些日期中每一天的气温增加 $d$。这种微小的改动可能不会被社区察觉,但同时它应该能使 LIS 更长。允许选择 $d = 0$。

修改后 LIS 的最大可能长度是多少?

输入格式

第一行包含两个空格分隔的整数 $n$ 和 $x$($1 \le n \le 200\,000$,$0 \le x \le 10^9$),分别表示天数和 $d$ 的绝对值上限。

第二行包含 $n$ 个空格分隔的整数 $t_1, t_2, \dots, t_n$($1 \le t_i \le 10^9$),表示历史气温序列。

输出格式

输出一个整数,表示进行一次修改后 LIS 的最大可能长度。

样例

样例输入 1

8 10
7 3 5 12 2 7 3 4

样例输出 1

5

说明

Johnny 可以选择区间 $[2, 3]$ 和 $d = -5$,这意味着将 $t_2$ 和 $t_3$ 减去 5。在这种情况下,新序列为 $(7, -2, 0, 12, 2, 7, 3, 4)$,他可以在其中找到一个 LIS $(-2, 0, 2, 3, 4)$。该 LIS 的长度为 5。

子任务

测试集分为以下子任务,包含附加约束。每个子任务中的测试由一个或多个独立的测试组组成。每个测试组可能包含一个或多个测试用例。

子任务 约束 分值
1 $n, x \le 10$ 5
2 $n, x \le 50$ 10
3 $n \le 1000$ 13
4 $x = 0$ 10
5 $x \le 5, n \le 50\,000$ 20
6 $x = 10^9$ 17
7 无附加约束 25

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.