#3177. Mandarin Orange

0
    ID: 3177 传统题 1000ms 1024MiB 尝试: 0 已通过: 0 难度: 2 上传者: 标签>AtCoderabc189CGESP 3级数组枚举(双层循环)

Mandarin Orange

Mandarin Orange

题目描述

There are NN dishes arranged in a row in front of Takahashi. The ii-th dish from the left has AiA_i oranges on it. Takahashi will choose a triple of integers (l,r,x)(l, r, x) satisfying all of the following conditions:

1≤l≤r≤N1\leq l \leq r \leq N; 1≤x1 \le x; for every integer ii between ll and rr (inclusive), x≤Aix \le A_i.

He will then pick up and eat xx oranges from each of the ll-th through rr-th dishes from the left. At most how many oranges can he eat by choosing the triple (l,r,x)(l, r, x) to maximize this number?

输入格式

Input is given from Standard Input in the following format: NN A1A_1 …\ldots ANA_N

输出格式

Print the maximum number of oranges Takahashi can eat.

6
2 4 4 9 4 9
20
6
200 4 4 9 4 9
200

提示

All values in input are integers. 1≤N≤1041 \leq N \leq 10^4 1≤Ai≤1051 \leq A_i \leq 10^5By choosing (l,r,x)=(2,6,4)(l,r,x)=(2,6,4), he can eat 2020 oranges.
By choosing (l,r,x)=(1,1,200)(l,r,x)=(1,1,200), he can eat 200200 oranges.

标签: AtCoder|abc189C

来源

AtCoder|abc189C