302071: CF392D. Three Arrays
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Three Arrays
题意翻译
给定三个长度为 $n$ 的数组 $A, B, C$,求使得 $u + v + w$ 最小的 $u, v, w$,满足 $A_{1\cdots u}, B_{1\cdots v}, C_{1\cdots w}$ 的并集等于 $A, B, C$ 的并集。题目描述
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 $ .输入输出格式
输入格式
The first line contains a single integer $ n $ $ (1<=n<=10^{5}) $ . 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}<=10^{9} $ .
输出格式
Print a single integer — the minimum possible sum of $ 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