#P5978. Maximizing Strictly Increasing Subsequence
Maximizing Strictly Increasing Subsequence
Maximizing Strictly Increasing Subsequence
Given an integer n and an array a of length n, you are allowed to perform at most one operation. In this operation, you may choose any contiguous subarray \(a_l, a_{l+1}, \dots, a_r\) (\(1 \le l \le r \le n\)) and add an integer \(d\) to each element in that subarray, where \(-x \le d \le x\). Your task is to maximize the length of the longest strictly increasing subsequence (LIS) of the array after performing at most one such operation.
Note: The operation is optional, i.e. you may choose not to perform any modification.
inputFormat
The first line contains two integers \(n\) and \(x\), where \(n\) is the length of the array and \(x\) restricts the chosen addition \(d\) (i.e. \(-x \le d \le x\)).
The second line contains \(n\) integers representing the array \(a\).
outputFormat
Output a single integer — the maximum possible length of the longest strictly increasing subsequence after at most one operation.
sample
5 2
1 2 3 2 1
4