Financial Report
Time limit2sMemory limit512 MB
Choose days that include the last day N, with consecutive picks at most D days apart, to maximize how many chosen days set a new record-high sales amount.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Segment tree
- Solved
- No attempts yet
Problem
JOI mart is a shop with N days of history. After it opened, the sales amount on the i-th day (1 ≤ i ≤ N) was yen.
Bitaro is the shop manager of JOI mart. He will make a presentation of the financial report. He chooses some days and shows a bar chart of their sales amounts in chronological order, then explains how the sales changed over those days. He wants the presentation to leave a strong impression, so he picks the data carefully.
Suppose he chooses the sales data for days (1 ≤ m ≤ N), namely days after opening, where . The impression score of the bar chart is the number of indices (1 ≤ j ≤ m) such that or . In other words, it counts how many chosen days set a new record-high sales amount.
Bitaro must satisfy both conditions:
- He shows the latest sales amount, so .
- For consecutive chosen days, the gap is at most D days. If , then for every .
Given the sales data and D, find the maximum impression score over all valid choices.
Input
Read the following data from standard input. All values are integers.
N D
A_1 A_2 ... A_N
Output
Write one line to standard output containing the maximum impression score.
Constraints
- 1 ≤ N ≤ 300000.
- 1 ≤ D ≤ N.
- 0 ≤ ≤ 1000000000 (1 ≤ i ≤ N).