CF1638F.Two Posters

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You want to advertise your new business, so you are going to place two posters on a billboard in the city center. The billboard consists of nn vertical panels of width 11 and varying integer heights, held together by a horizontal bar. The ii -th of the nn panels has height hih_i .

Initially, all panels hang down from the bar (their top edges lie on it), but before placing the two posters, you are allowed to move each panel up by any integer length, as long as it is still connected to the bar (its bottom edge lies below or on it).

After the moves are done, you will place two posters: one below the bar and one above it. They are not allowed to go over the bar and they must be positioned completely inside of the panels.

What is the maximum total area the two posters can cover together if you make the optimal moves? Note that you can also place a poster of 00 area. This case is equivalent to placing a single poster.

输入格式

The first line of input contains one integer nn ( 1n1041 \le n \le 10^4 ) — the number of vertical panels.

The second line of input contains nn integers h1,h2,...,hnh_1, h_2, ..., h_n ( 1hi10121 \le h_i \le 10^{12} ) — the heights of the nn vertical panels.

输出格式

Print a single integer — the maximum total area the two posters can cover together.

输入输出样例

  • 输入#1

    6
    2 2 3 5 4 5

    输出#1

    18
  • 输入#2

    1
    1

    输出#2

    1

说明/提示

In the first sample test, we can choose an upper poster with area 1212 and a lower poster of area 66 as in the image below.

In the second sample test, we can cover the whole billboard using a single poster.

首页