luogu#P8102. 「LCOI2022」 Cow Insertion
「LCOI2022」 Cow Insertion
Background
Farmer John has welcomed a new cow, Bessie. Each cow has a certain happiness value, and Farmer John hopes that Bessie can live a happier life here.
Problem Description
There are originally cows in the barn, with a happiness influence distance of . Let denote the happiness value of the -th cow in the original barn. Bessie also has a happiness value .
The total happiness of the whole barn is defined as $\sum\limits_{i=1}^{n-m+1}\ \max\limits_{i\le j\le i+m-1}\ a_j$. Bessie can be placed between any two cows, or at the beginning or the end. Farmer John wants to know: after Bessie comes here, what is the maximum possible total happiness of the whole barn.
Input Format
The first line contains three integers , representing the number of cows, the happiness influence distance, and Bessie's happiness value.
The next line contains numbers , representing the happiness value of the -th cow in the original barn.
Output Format
Output a single line representing the maximum total happiness of the whole barn after Bessie comes here.
3 2 50
60 100 70
270
Hint
[Sample Explanation]
- When Bessie is in the first position (), the maximum total happiness of the whole barn is $\newcommand{\cases}[1]{\{#1\}}\max\cases{60,50}+\max\cases{60,100}+\max\cases{100,70}$, i.e., .
- When Bessie is in the second position (), the maximum total happiness of the whole barn is $\newcommand{\cases}[1]{\{#1\}}\max\cases{60,50}+\max\cases{50,100}+\max\cases{100,70}$, i.e., .
- When Bessie is in the third position (), the maximum total happiness of the whole barn is $\newcommand{\cases}[1]{\{#1\}}\max\cases{60,100}+\max\cases{100,50}+\max\cases{50,70}$, i.e., .
- When Bessie is in the fourth position (), the maximum total happiness of the whole barn is $\newcommand{\cases}[1]{\{#1\}}\max\cases{60,100}+\max\cases{100,70}+\max\cases{70,50}$, i.e., .
Clearly, the maximum total happiness of the whole barn is $\newcommand{\cases}[1]{\{#1\}}\max\cases{260,260,270,270}=270$.
[Constraints and Notes]
| subtask | points | |
|---|---|---|
For of the testdata, , and .
Translated by ChatGPT 5