题库练习 3SUM Closure
← 上一题 下一题 →

A15249 | 3SUM Closure

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

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 $a_i + a_j + a_k$ is an element of the array. More formally, $a$ is 3SUM-closed if for all integers $1 \leq i < j < k \leq n$ , there exists some integer $1 \leq l \leq n$ such that $a_i + a_j + a_k = a_l$ .

Determine if $a$ is 3SUM-closed.

输入格式

The first line contains an integer $t$ ( $1 \leq t \leq 1000$ ) — the number of test cases.

The first line of each test case contains an integer $n$ ( $3 \leq n \leq 2 \cdot 10^5$ ) — the length of the array.

The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ( $-10^9 \leq a_i \leq 10^9$ ) — the elements of the array.

It is guaranteed that the sum of $n$ across all test cases does not exceed $2 \cdot 10^5$ .

输出格式

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
C++ 编辑器
输入
输出