#P15278. [MCO 2025] Subsequence

    ID: 15296 远端评测题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划 DP线段树2025MCC/MCO(马来西亚)

[MCO 2025] Subsequence

Description

Given an array aa and an integer XX, you are tasked to find the longest valid\textbf{valid} subsequence of the array aa. A subsequence is valid\textbf{valid} if and only if none of the products of neighbouring elements in the subsequence exceed XX. That is, suppose bb is the subsequence of aa with length mm, bb is valid\textbf{valid} if and only if for any ii, where 1im11 \leq i \leq m-1, bibi+1Xb_i \cdot b_{i+1} \leq X.

Note: An array bb is a subsequence of another array aa if bb can be created by removing some elements (possibly none) from array aa without changing the order of elements. For example, the array [1,3][1,3] is a subsequence of [1,2,3][1,2,3], whereas the array [2,1][2,1] and the array [1,4][1,4] is \textbf{not} a subsequence of [1,2,3][1,2,3].

Input Format

The first line contains two space-seperated integers, nn (1n1051 \leq n \leq 10^5) and XX (0X10180 \leq |X| \leq 10^{18}) -- nn is the length of array aa and XX is the integer given.

The second line contains nn space-seperated integers, a1,a2,,ana_1, a_2, \dots, a_n (1ai1091 \leq |a_i| \leq 10^9).

Output Format

The only line contains an integer, which is the length of the longest valid\textbf{valid} subsequence.

1 10
100
1
5 10
3 4 2 5 1
4
5 10
6 -2 -2 -6 5
4

Hint

Note

Example1\underline{Example 1}\\ A subsequence of one element is always valid because there are no neighbouring elements. Therefore, the length of the longest valid\textbf{valid} subsequence is 11.

Example2\underline{Example 2}\\ This example has a valid\textbf{valid} subsequence, [3,2,5,1][3,2,5,1]. It is because the product of the neighbouring elements does not exceed 1010, as shown below.

  • 3×2=6(10)3 \times 2 = 6 \,(\leq 10)
  • 2×5=10(10)2 \times 5 = 10 \,(\leq 10)
  • 5×1=5(5)5 \times 1 = 5 \,(\leq 5)

The subsequence [3,4,2,5,1][\underline{3,4},2,5,1] (i.e., the original array aa) is invalid\textbf{invalid} because the product of the first and second elements is 12, which exceeds 1010.

Therefore, the length of the longest valid\textbf{valid} subsequence is 44.

Example3\underline{Example 3}\\ The longest valid\textbf{valid} subsequence is [6,2,2,5][6,-2,-2,5].

The subsequence [6,2,2,6,5][6,-2,\underline{-2, -6}, 5] (i.e., the original array aa) is invalid\textbf{invalid} because the product of the third and fourth elements is 2×6=12-2 \times -6 = 12, which exceeds 1010.

Scoring

Subtask 1 (55 points): X=1018X = 10^{18}

Subtask 2 (1515 points): n20n \leq 20

Subtask 3 (2020 points): n103n \leq 10^3

Subtask 4 (1010 points): X0X \geq 0 and 1ai2001 \leq a_i \leq 200, for all 1in1 \leq i \leq n

Subtask 5 (2020 points): X0X \geq 0 and 1ai1051 \leq a_i \leq 10^5, for all 1in1 \leq i \leq n

Subtask 6 (1010 points): X0X \geq 0 and ai1a_i \geq 1, for all 1in1 \leq i \leq n

Subtask 7 (2020 points): No additional constraints