CF987C.Three displays
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 si 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 si<sj<sk should be held.
The rent cost is for the i-th display is ci. Please determine the smallest cost Maria Stepanovna should pay.
现在是2018年年中,住在克拉斯诺卡缅斯克(外贝加尔边疆区的一座城镇)郊外的玛丽亚·斯捷潘诺夫娜想要租用三块显示屏,以突出一个重要的问题。
沿道路共放置了 n 块显示屏,其中第 i 块显示屏只能显示字体大小为 si 的文本。玛丽亚·斯捷潘诺夫娜希望租用三块显示屏,其下标满足 i<j<k,且当沿道路朝某一方向行进时,字体大小严格递增,即满足条件 si<sj<sk。
第 i 块显示屏的租金为 ci。请计算玛丽亚·斯捷潘诺夫娜所需支付的最小总租金。
输入格式
The first line contains a single integer n (3≤n≤3000) — the number of displays.
The second line contains n integers s1,s2,…,sn (1≤si≤109) — the font sizes on the displays in the order they stand along the road.
The third line contains n integers c1,c2,…,cn (1≤ci≤108) — the rent costs for each display.
第一行包含一个整数 n(3≤n≤3000)—— 显示屏的数量。
第二行包含 n 个整数 s1,s2,…,sn(1≤si≤109)—— 沿道路排列的显示屏上的字体大小(按顺序给出)。
第三行包含 n 个整数 c1,c2,…,cn(1≤ci≤108)—— 每个显示屏的租金成本。
输出格式
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 si<sj<sk.
如果没有三个显示屏满足条件,则输出 -1。否则,输出一个整数——满足下标 i<j<k 且 si<sj<sk 的三个显示屏的最小总租金成本。
输入输出样例
输入#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 s1<s4<s5 (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.
在第一个例子中,例如可以选择显示器 1、4 和 5,因为 s1<s4<s5(即 2<4<10),且租金总成本为 40+10+40=90。
在第二个例子中,无法选出满足条件的三元组下标,因此答案为 −1。
输入解题思路,AI测评打分。不知道怎么写?