CF1641D.Two Arrays
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Sam changed his school and on the first biology lesson he got a very interesting task about genes.
You are given n arrays, the i -th of them contains m different integers — ai,1,ai,2,…,ai,m . Also you are given an array of integers w of length n .
Find the minimum value of wi+wj among all pairs of integers (i,j) ( 1≤i,j≤n ), such that the numbers ai,1,ai,2,…,ai,m,aj,1,aj,2,…,aj,m are distinct.
输入格式
The first line contains two integers n , m ( 2≤n≤105 , 1≤m≤5 ).
The i -th of the next n lines starts with m distinct integers ai,1,ai,2,…,ai,m and then wi follows ( 1≤ai,j≤109 , 1≤wi≤109 ).
输出格式
Print a single number — the answer to the problem.
If there are no suitable pairs (i,j) , print −1 .
输入输出样例
输入#1
4 2 1 2 5 4 3 1 2 3 2 4 5 3
输出#1
5
输入#2
4 3 1 2 3 5 2 3 4 2 3 4 5 3 1 3 10 10
输出#2
-1
说明/提示
In the first test the minimum value is 5=w3+w4 , because numbers {2,3,4,5} are distinct.
In the second test case, there are no suitable pair (i,j) .