Mandarin Orange

AtCoder
IDabc189_c
Time1500ms
Memory256MB
Difficulty
There are $N$ dishes arranged in a row in front of Takahashi. The $i$\-th dish from the left has $A_i$ oranges on it. Takahashi will choose a triple of integers $(l, r, x)$ satisfying all of the following conditions: * $1\leq l \leq r \leq N$; * $1 \le x$; * for every integer $i$ between $l$ and $r$ (inclusive), $x \le A_i$. He will then pick up and eat $x$ oranges from each of the $l$\-th through $r$\-th dishes from the left. At most how many oranges can he eat by choosing the triple $(l, r, x)$ to maximize this number? ## Constraints * All values in input are integers. * $1 \leq N \leq 10^4$ * $1 \leq A_i \leq 10^5$ ## Input Input is given from Standard Input in the following format: $N$ $A_1$ $\ldots$ $A_N$ [samples]
Samples
Input #1
6
2 4 4 9 4 9
Output #1
20

By choosing $(l,r,x)=(2,6,4)$, he can eat $20$ oranges.
Input #2
6
200 4 4 9 4 9
Output #2
200

By choosing $(l,r,x)=(1,1,200)$, he can eat $200$ oranges.
API Response (JSON)
{
  "problem": {
    "name": "Mandarin Orange",
    "description": {
      "content": "There are $N$ dishes arranged in a row in front of Takahashi. The $i$\\-th dish from the left has $A_i$ oranges on it. Takahashi will choose a triple of integers $(l, r, x)$ satisfying all of the follo",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 1500,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc189_c"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "There are $N$ dishes arranged in a row in front of Takahashi. The $i$\\-th dish from the left has $A_i$ oranges on it.\nTakahashi will choose a triple of integers $(l, r, x)$ satisfying all of the follo...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments