#K54612. Maximum Warrior Pairs
Maximum Warrior Pairs
Maximum Warrior Pairs
You are given a list of warriors, where each warrior is characterized by an integer representing their strength. Your task is to form as many valid pairs of warriors as possible. A pair of warriors \( (a, b) \) is considered valid if the strength of warrior \(a\) is strictly greater than the strength of warrior \(b\), i.e., \(a > b\).
You need to determine the maximum number of valid pairs that can be formed from the given list. Each warrior can be used at most once in a pair.
Note: The problem can be solved efficiently by first sorting the list and then using a two-pointer strategy to count the pairs.
inputFormat
The input is given from standard input (stdin) and has the following format:
- The first line contains an integer \(n\) indicating the number of warriors.
- The second line contains \(n\) space-separated integers representing the strengths of the warriors.
outputFormat
Output a single integer to standard output (stdout) which denotes the maximum number of valid warrior pairs that can be formed.
## sample5
1 2 3 4 5
2