CF392D.Three Arrays
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are three arrays a, b and c. Each of them consists of n integers. SmallY wants to find three integers u, v, w (0 ≤ u, v, w ≤ n) such that the following condition holds: each number that appears in the union of a, b and c, appears either in the first u elements of a, or in the first v elements of b, or in the first w elements of c. Of course, SmallY doesn't want to have huge numbers u, v and w, so she wants sum u + v + w to be as small as possible.
Please, help her to find the minimal possible sum of u + v + w.
有三个数组 a、b 和 c,每个数组均包含 n 个整数。SmallY 希望找到三个整数 u、v、w(满足 0 ≤ u,v,w ≤ n),使得以下条件成立:在 a、b、c 的并集中出现的每一个数,都必须至少出现在 a 的前 u 个元素中、或 b 的前 v 个元素中、或 c 的前 w 个元素中。当然,SmallY 不希望 u、v、w 过大,因此她希望使和 u + v + w 尽可能小。
请帮助她找出 u + v + w 的最小可能值。
输入格式
The first line contains a single integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers _a_1, _a_2, ..., a__n — array a. The third line contains the description of array b in the same format. The fourth line contains the description of array c in the same format. The following constraint holds: 1 ≤ a__i, b__i, c__i ≤ 109.
第一行包含一个整数 n(1≤n≤105)。
第二行包含 n 个以空格分隔的整数 a1,a2,…,an —— 数组 a。
第三行以相同格式给出数组 b 的描述。
第四行以相同格式给出数组 c 的描述。
以下约束成立:1≤ai,bi,ci≤109。
输出格式
Print a single integer — the minimum possible sum of u + v + w.
输出一个整数——u+v+w 的最小可能和。
输入输出样例
输入#1
3 1 1 101 1 2 1 3 2 1
输出#1
5
输入#2
5 1 1 2 2 3 2 2 4 3 3 3 3 1 1 1
输出#2
5
说明/提示
In the first example you should choose u = 3, v = 0, w = 2.
In the second example you should choose u = 1, v = 3, w = 1.
在第一个例子中,你应该选择 u=3,v=0,w=2。
在第二个例子中,你应该选择 u=1,v=3,w=1。
输入解题思路,AI测评打分。不知道怎么写?