#P7804. [JOI Open 2021] 决算报告 / Financial Report

[JOI Open 2021] 决算报告 / Financial Report

Description

There is a sequence AiA_i of length NN. Define the value of the function f(m,p1,p2,,pm)f(m,p_1,p_2,\cdots,p_m) as the number of indices pip_i that satisfy:

maxj=1i1{Apj}<Api\max\limits_{j=1}^{i-1}\{A_{p_j}\} < A_{p_i}

When i=1i=1, we assume that the inequality above always holds.

Given an integer DD, find a sequence pip_i that satisfies:

  • 1mN1 \le m \le N;
  • pm=Np_m = N;
  • pi<pi+1p_i < p_{i+1};
  • If m2m \ge 2, then pj+1pjDp_{j+1} - p_j \le D;
  • The value of f(m,p1,p2,,pm)f(m,p_1,p_2,\dots,p_m) is maximized.

Output the maximum value of the function ff.

Input Format

The first line contains two integers N,DN, D, with the meaning as described in the statement.

The second line contains NN integers AiA_i, representing the given sequence.

Output Format

Output one integer on a single line, representing the maximum value of the function ff.

7 1
100 600 600 200 300 500 500
3
6 6
100 500 200 400 600 300
4
11 2
1 4 4 2 2 4 9 5 7 0 3
4

Hint

Sample 1 Explanation

There are 77 possible cases in total:

  • pi={1,2,3,4,5,6,7}p_i=\{1,2,3,4,5,6,7\}, f(7,1,2,3,4,5,6,7)=2f(7,1,2,3,4,5,6,7)=2;
  • pi={2,3,4,5,6,7}p_i=\{2,3,4,5,6,7\}, f(6,2,3,4,5,6,7)=1f(6,2,3,4,5,6,7)=1;
  • pi={3,4,5,6,7}p_i=\{3,4,5,6,7\}, f(5,3,4,5,6,7)=1f(5,3,4,5,6,7)=1;
  • pi={4,5,6,7}p_i=\{4,5,6,7\}, f(4,4,5,6,7)=3f(4,4,5,6,7)=3;
  • pi={5,6,7}p_i=\{5,6,7\}, f(3,5,6,7)=2f(3,5,6,7)=2;
  • pi={6,7}p_i=\{6,7\}, f(2,6,7)=1f(2,6,7)=1;
  • pi={7}p_i=\{7\}, f(1,7)=1f(1,7)=1.

The maximum value is 33.

Sample 2 Explanation

The optimal pi={1,3,4,5,6}p_i=\{1,3,4,5,6\}. The corresponding Ai={100,200,400,600,300}A_i=\{100,200,400,600,300\}, and the value of ff is 44.

Sample 3 Explanation

There are multiple optimal ways. One of them is pi={1,3,5,6,8,9,11}p_i=\{1,3,5,6,8,9,11\}. The corresponding Ai={1,4,2,4,5,7,3}A_i=\{ 1, 4, 2, 4, 5, 7, 3\}, and the value of ff is 44.

Constraints

This problem uses bundled testdata.

  • Subtask 1 (14 pts): N20N \le 20;
  • Subtask 2 (14 pts): N400N \le 400;
  • Subtask 3 (20 pts): N7000N \le 7000;
  • Subtask 4 (12 pts): D=1D = 1;
  • Subtask 5 (5 pts): D=ND = N;
  • Subtask 6 (35 pts): no special restrictions.

For 100%100\% of the testdata:

  • 1N3×1051 \le N \le 3 \times 10^5;
  • 1DN1 \le D \le N;
  • 0Ai1090 \le A_i \le 10^9.

Notes

Translated from JOI 2020 / 2021 Open Contest B Financial Report.

Translated by ChatGPT 5