#C5513. Maximum Team Skill

    ID: 49171 Type: Default 1000ms 256MiB

Maximum Team Skill

Maximum Team Skill

You are given a list of participants, each characterized by a role and a skill level. The role is represented by a character: C for coach and P for player. A team is valid if it contains at least one coach and at least one player. The team's overall skill is defined as the sum of the highest coach skill and the highest player skill. Formally, if \(C\) is the set of skills of coaches and \(P\) is the set of skills of players, then the answer is given by:

[ \max_{c \in C} c + \max_{p \in P} p ]

If either C or P is empty, then no valid team can be formed and the answer should be -1.

inputFormat

The input is read from standard input (stdin) and is structured as follows:

  • The first line contains an integer \(n\) representing the number of participants.
  • The following \(n\) lines each contain a character and an integer separated by a space. The character is either C (coach) or P (player), and the integer represents the corresponding skill level.

outputFormat

Output a single integer to standard output (stdout): the maximum team skill level if a valid team can be formed, or -1 otherwise.

## sample
5
C 5
P 3
P 8
C 2
C 6
14