#P8776. [蓝桥杯 2022 省 A] 最长不下降子序列

    ID: 9694 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划 DP线段树2022蓝桥杯省赛

[蓝桥杯 2022 省 A] 最长不下降子序列

Problem Description

Given an integer sequence of length NN: A1,A2,,ANA_{1}, A_{2}, \cdots, A_{N}. You now have one chance to modify KK consecutive numbers in it to any same value. Please compute how to modify it so that the longest non-decreasing subsequence of the modified sequence is as long as possible, and output this maximum length.

A longest non-decreasing subsequence means a subsequence of the sequence, where each number in the subsequence is not less than the number before it.

Input Format

The first line contains two integers NN and KK.

The second line contains NN integers A1,A2,,ANA_{1}, A_{2}, \cdots, A_{N}.

Output Format

Output one line containing one integer, representing the answer.

5 1
1 4 2 8 5
4

Hint

For 20%20\% of the testdata, 1KN1001 \leq K \leq N \leq 100.

For 30%30\% of the testdata, 1KN10001 \leq K \leq N \leq 1000.

For 50%50\% of the testdata, 1KN100001 \leq K \leq N \leq 10000.

For all testdata, 1KN1051 \leq K \leq N \leq 10^{5}, 1Ai1061 \leq A_{i} \leq 10^{6}.

Lanqiao Cup 2022 Provincial Contest, Group A, Problem G.

Translated by ChatGPT 5