What is the value of my FIFA team?
Time limit1sMemory limit1024 MB
Given players with positions and values, simulate K yearly rebuilds where each starter loses 1 value per year, then sum the starter values after year K.
- Level
Medium5 of 10
- Topics
- Heap, Simulation
- Solved
- No attempts yet
Problem
Nexon's FIFA ONLINE 4 is a game that lets players enjoy vivid soccer match simulations. Each player has a position, along with ability stats and a player value that affect matches. Teams also split players into starters and substitutes, and a starter in poor condition can be swapped out for a substitute.

Joowon plays FIFA ONLINE 4 and wants to know the total value of the starters in December of year if he builds his team with the following process.
- A team has 11 players, and position numbers are integers from 1 to 11.
- In March, the player with the highest value in each position becomes the starter. If several players share the highest value, pick any one of them as the starter.
- If no player fits a position, the team is formed with that position left empty.
- In August, the value of every current starter drops by 1. A player value never goes below 0.
- In November, rebuild the starters using rule 2.
Given players with their positions and values, the team is rebuilt with the process above in each year . Find the sum of the starter values of the team formed in December of year .
Input
The first line contains and separated by a space.
From the second line onward, each of the next lines contains the position and the value of the -th player, separated by a space.
All input values are integers.
Output
Print the sum of the starter values of the team formed in December of year .