CF1698C.3SUM Closure
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a of length n . The array is called 3SUM-closed if for all distinct indices i , j , k , the sum ai+aj+ak is an element of the array. More formally, a is 3SUM-closed if for all integers 1≤i<j<k≤n , there exists some integer 1≤l≤n such that ai+aj+ak=al .
Determine if a is 3SUM-closed.
输入格式
The first line contains an integer t ( 1≤t≤1000 ) — the number of test cases.
The first line of each test case contains an integer n ( 3≤n≤2⋅105 ) — the length of the array.
The second line of each test case contains n integers a1,a2,…,an ( −109≤ai≤109 ) — the elements of the array.
It is guaranteed that the sum of n across all test cases does not exceed 2⋅105 .
输出格式
For each test case, output "YES" (without quotes) if a is 3SUM-closed and "NO" (without quotes) otherwise.
You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
输入输出样例
输入#1
4 3 -1 0 1 5 1 -2 -2 1 -3 6 0 0 0 0 0 0 4 -1 2 -3 4
输出#1
YES NO YES NO
说明/提示
In the first test case, there is only one triple where i=1 , j=2 , k=3 . In this case, a1+a2+a3=0 , which is an element of the array ( a2=0 ), so the array is 3SUM-closed.
In the second test case, a1+a4+a5=−1 , which is not an element of the array. Therefore, the array is not 3SUM-closed.
In the third test case, ai+aj+ak=0 for all distinct i , j , k , and 0 is an element of the array, so the array is 3SUM-closed.