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.

有三个数组 aa、bb 和 cc,每个数组均包含 nn 个整数。SmallY 希望找到三个整数 uu、vv、ww(满足 0 ≤ u, v, w ≤ n0 \leq u,\,v,\,w \leq n),使得以下条件成立:在 aa、bb、cc 的并集中出现的每一个数,都必须至少出现在 aa 的前 uu 个元素中、或 bb 的前 vv 个元素中、或 cc 的前 ww 个元素中。当然,SmallY 不希望 uu、vv、ww 过大,因此她希望使和 u + v + wu + v + w 尽可能小。

请帮助她找出 u + v + wu + 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.

第一行包含一个整数 nn(1≤n≤1051 \leq n \leq 10^5)。
第二行包含 nn 个以空格分隔的整数 a1, a2, …, ana_1,\,a_2,\,\dots,\,a_n —— 数组 aa。
第三行以相同格式给出数组 bb 的描述。
第四行以相同格式给出数组 cc 的描述。
以下约束成立:1≤ai, bi, ci≤1091 \leq a_i,\,b_i,\,c_i \leq 10^9。

输出格式

Print a single integer — the minimum possible sum of u + v + w.

输出一个整数——u+v+wu + 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=3u = 3,v=0v = 0,w=2w = 2。

在第二个例子中,你应该选择 u=1u = 1,v=3v = 3,w=1w = 1。

输入解题思路,AI测评打分。不知道怎么写?

首页