A14953 | Two Posters
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $n$ vertical panels of width $1$ and varying integer heights, held together by a horizontal bar. The $i$ -th of the $n$ panels has height $h_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 $0$ area. This case is equivalent to placing a single poster.
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 $0$ area. This case is equivalent to placing a single poster.
输入格式
The first line of input contains one integer $n$ ( $1 \le n \le 10^4$ ) — the number of vertical panels.
The second line of input contains $n$ integers $h_1, h_2, ..., h_n$ ( $1 \le h_i \le 10^{12}$ ) — the heights of the $n$ vertical panels.
The second line of input contains $n$ integers $h_1, h_2, ..., h_n$ ( $1 \le h_i \le 10^{12}$ ) — the heights of the $n$ 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 $12$ and a lower poster of area $6$ as in the image below.
In the second sample test, we can cover the whole billboard using a single poster.
In the second sample test, we can cover the whole billboard using a single poster.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted