#C5606. Maximum Valid Teams
Maximum Valid Teams
Maximum Valid Teams
Problem Description:
Given n participants, each with a positive integer strength, your task is to form as many valid teams as possible. A valid team consists of exactly three participants such that if the three strengths are denoted by a, b, and c (with a ≤ b ≤ c), then the triangle inequality holds:
( c < a + b )
This ensures that the sum of the two smaller strengths is greater than the largest strength. Each participant can be used in at most one team. Your goal is to maximize the number of valid teams formed under these constraints.
inputFormat
Input is read from standard input (stdin) and consists of two lines. The first line contains a single integer n representing the number of participants. The second line contains n space-separated integers, where each integer denotes the strength of a participant.
outputFormat
Output to standard output (stdout) a single integer representing the maximum number of valid teams that can be formed.## sample
7
10 20 30 40 50 60 70
2
</p>