#C11921. Three Sum Problem

    ID: 41291 Type: Default 1000ms 256MiB

Three Sum Problem

Three Sum Problem

Given an array of integers, your task is to find all unique triplets \(a, b, c\) in the array such that \(a + b + c = 0\). Each triplet should be output in non-decreasing order (i.e. \(a \le b \le c\)), and duplicate triplets must be excluded.

Note: The solution should run in efficient time. You may find sorting the array and then using a two-pointer technique helpful.

inputFormat

The first line contains an integer \(n\) representing the number of elements in the array. The second line contains \(n\) space-separated integers.

outputFormat

If there exists at least one triplet such that the sum of its three elements is zero, print each triplet in a separate line with the three numbers separated by a space. The triplets must be printed in non-decreasing lexicographical order. If no such triplet is found, output No triplets found.

## sample
6
-1 0 1 2 -1 -4
-1 -1 2

-1 0 1

</p>