A11824 | Three displays
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.
There are $n$ displays placed along a road, and the $i$ -th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent such three displays with indices $i < j < k$ that the font size increases if you move along the road in a particular direction. Namely, the condition $s_i < s_j < s_k$ should be held.
The rent cost is for the $i$ -th display is $c_i$ . Please determine the smallest cost Maria Stepanovna should pay.
There are $n$ displays placed along a road, and the $i$ -th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent such three displays with indices $i < j < k$ that the font size increases if you move along the road in a particular direction. Namely, the condition $s_i < s_j < s_k$ should be held.
The rent cost is for the $i$ -th display is $c_i$ . Please determine the smallest cost Maria Stepanovna should pay.
输入格式
The first line contains a single integer $n$ ( $3 \le n \le 3\,000$ ) — the number of displays.
The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ( $1 \le s_i \le 10^9$ ) — the font sizes on the displays in the order they stand along the road.
The third line contains $n$ integers $c_1, c_2, \ldots, c_n$ ( $1 \le c_i \le 10^8$ ) — the rent costs for each display.
The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ( $1 \le s_i \le 10^9$ ) — the font sizes on the displays in the order they stand along the road.
The third line contains $n$ integers $c_1, c_2, \ldots, c_n$ ( $1 \le c_i \le 10^8$ ) — the rent costs for each display.
输出格式
If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integer — the minimum total rent cost of three displays with indices $i < j < k$ such that $s_i < s_j < s_k$ .
输入输出样例
输入 #1
5 2 4 5 4 10 40 30 20 10 40
输出 #1
90
输入 #2
3 100 101 100 2 4 5
输出 #2
-1
输入 #3
10 1 2 3 4 5 6 7 8 9 10 10 13 11 14 15 12 13 13 18 13
输出 #3
33
In the first example you can, for example, choose displays $1$ , $4$ and $5$ , because $s_1 < s_4 < s_5$ ( $2 < 4 < 10$ ), and the rent cost is $40 + 10 + 40 = 90$ .
In the second example you can't select a valid triple of indices, so the answer is -1.
In the second example you can't select a valid triple of indices, so the answer is -1.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted