

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
長さ の正整数列 が与えられます。
また、長さ の正整数列が 個与えられます。 個目の正整数列は です。
あなたは の順に以下の操作のうちどちらかを行います。どちらを選ぶかは各 に対して独立に決めることが出来ます。
- を満たす全ての整数 に対して を に置き換える。
- を満たす全ての整数 に対して を に置き換える。
操作終了時の の最小値を求めてください。
制約
入力
入力は以下の形式で標準入力から与えられる。
出力
答えを出力せよ。
入力例 1Copy
3 2 4 4 2 3 1 5 2 5 2 1 2 4
出力例 1Copy
21
最適な操作列の一例として、以下のようなものがあります。
- を に置き換える。 となる。
- を に置き換える。 となる。
このように操作をすると、 が達成できます。
入力例 2Copy
3 5 4 13 10 14 9 4 4 6 4 13 18 16 8 13 5 7 18 17 20 20 14
出力例 2Copy
84
入力例 3Copy
5 12 330 68 248 387 491 295 366 376 262 192 280 121 17 168 455 288 179 210 378 490 150 275 165 264 287 66 331 207 282 367 303 215 456 214 18 227 326 103 443 427 395 57 107 350 227 318 231 146 2 116 57 325 124 383 260 147 319 23 177 445 254 198 32 85 56 68 177 356 41 471
出力例 3Copy
3595
Score: points
Problem Statement
You are given two length- sequences of positive integers: and .
Additionally, you are given length- sequences of positive integers. The -th sequence is .
For each , you must perform one of the following operations. You can independently choose which operation to perform for each .
- Replace with for all integers such that .
- Replace with for all integers such that .
Find the minimum possible value of after all operations.
Constraints
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1Copy
3 2 4 4 2 3 1 5 2 5 2 1 2 4
Sample Output 1Copy
21
One optimal sequence of operations is as follows:
- Replace with , making .
- Replace with , making .
This sequence of operations achieves .
Sample Input 2Copy
3 5 4 13 10 14 9 4 4 6 4 13 18 16 8 13 5 7 18 17 20 20 14
Sample Output 2Copy
84
Sample Input 3Copy
5 12 330 68 248 387 491 295 366 376 262 192 280 121 17 168 455 288 179 210 378 490 150 275 165 264 287 66 331 207 282 367 303 215 456 214 18 227 326 103 443 427 395 57 107 350 227 318 231 146 2 116 57 325 124 383 260 147 319 23 177 445 254 198 32 85 56 68 177 356 41 471
Sample Output 3Copy
3595