GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Tuesday 28 June 2022

[Solution] 3SUM Closure Codeforces Solution | Codeforces Problem Solution 2022


C. 3SUM Closure
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given an array a of length n. The array is called 3SUM-closed if for all distinct indices ijk, the sum ai+aj+ak is an element of the array. More formally, a is 3SUM-closed if for all integers 1i<j<kn, there exists some integer 1ln such that ai+aj+ak=al.

Determine if a is 3SUM-closed.

Input

The first line contains an integer t (1t1000) — the number of test cases.

The first line of each test case contains an integer n (3n2105) — the length of the array.

Solution Click Below:-  👉CLICK HERE👈
👇👇👇👇👇

The second line of each test case contains n integers a1,a2,,an (109ai109) — the elements of the array.

It is guaranteed that the sum of n across all test cases does not exceed 2105.

Output

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).

No comments:

Post a Comment