#P8590. 『JROI-8』这是新历的朝阳,也是旧历的残阳
『JROI-8』这是新历的朝阳,也是旧历的残阳
Background

The girl stands by the sea, gazing at the last glow of the setting sun.
"It has already passed, the year of the old calendar......"
Reprint authorization has been obtained.
Problem Description
Given a sequence where each term is not less than the previous term. For every positive integer with , ask: if we split the sequence into segments (empty segments are allowed), and then for the -th segment from left to right, add to every number in that segment, what is the maximum possible value of after the increment?
Each query is independent. That is, in each query, the value added to each number does not carry over to the next query.
For example, for the sequence , if , one possible segmentation is . The resulting sequence after increment is , and then .
Let the answer for (i.e., the maximum in this case) be . To be nice, you only need to output $\left(\sum\limits_{i=1}^k q_i\right) \bmod 998244353$. The standard solution is not based on this special output format, meaning it can compute each independently.
Input Format
The first line contains two positive integers , as described.
The next line contains integers, representing .
Output Format
Output one integer, which is $\left(\sum\limits_{i=1}^k q_i\right) \bmod 998244353$.
4 3
-3 1 2 2
141
Hint
Sample Explanation
When , the optimal strategy is , and .
When , the optimal strategy is , and .
When , the optimal strategy is , and .
So $\left(\sum\limits_{i=1}^k q_i\right) \bmod 998244353=(q_1+q_2+q_3)\bmod 998244353=(26+45+70)\bmod 998244353=141$.
Constraints
| Test Point ID | Score | Special Property | |||
|---|---|---|---|---|---|
| None | |||||
| None | |||||
Translated by ChatGPT 5