305189: CF987C. Three displays

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Three displays

题意翻译

### 题目大意 一个长为 $n\,(3\leq n\leq 3000)$ 的序列,每个数有两个性质 $s_i$ 和 $c_i$。找出一组 $\{i,j,k\}$,使得 $s_i<s_j<s_k$ 且 $c_i+c_j+c_k$ 最小。 ### 输入格式 第一行一个整数 $n$, 接下来一行 $n$ 个数,表示 $s_i$, 再接下来一行 $n$ 个数,表示 $c_i$。 ### 输出格式 一个整数,表示最小且满足题意的 $s_i+s_j+s_k$。

题目描述

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.

输入输出格式

输入格式


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.

输出格式


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.

Input

题意翻译

### 形式化题面 给定一个有两个性质 $s_i$ 和 $c_i$ 的数组,要求在其中选出三个数,满足: - $i<j<k$. - $s_i<s_j<s_k$. - $c_i+c_j+c_k$ 最小. ### 输入格式 第一行一个整数 $n$ 表示数组长度. 接下来一行 $n$ 个整数,表示 $s_i$. 接下来一行 $n$ 个整数,表示 $c_i$. ### 输出格式 一行一个整数,表示最小的 $c_i+c_j+c_k$ 翻译 @[zymooll](/user/289296)

加入题单

上一题 下一题 算法标签: