CF1641D.Two Arrays
省选/NOI-
通过率:0%
时间限制:3.00s
内存限制:512MB
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.
萨姆转学了,在第一节生物课上,他得到了一个关于基因的非常有趣的任务。
给你 n 个数组,其中第 i 个数组包含 m 个互不相同的整数:ai,1,ai,2,…,ai,m。此外,还给你一个长度为 n 的整数数组 w。
在所有满足以下条件的整数对 (i,j)(其中 1≤i,j≤n)中,求 wi+wj 的最小值:
数组 ai,1,ai,2,…,ai,m,aj,1,aj,2,…,aj,m 中的所有数互不相同。
输入格式
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).
第一行包含两个整数 n 和 m(2≤n≤105,1≤m≤5)。
接下来的 n 行中,第 i 行以 m 个互不相同的整数 ai,1,ai,2,…,ai,m 开头,随后是 wi(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.
输出一个数字——即该问题的答案。
如果没有满足条件的数对 (i,j),则输出 −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).
在第一个测试用例中,最小值为 5=w3+w4,因为数字 {2,3,4,5} 互不相同。
在第二个测试用例中,不存在满足条件的数对 (i,j)。
输入解题思路,AI测评打分。不知道怎么写?