Under construction

Still being built. Things may change

What is the value of my FIFA team?

Time limit1sMemory limit1024 MB

Summary
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 KK if he builds his team with the following process.

  1. A team has 11 players, and position numbers are integers from 1 to 11.
  2. 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.
  3. If no player fits a position, the team is formed with that position left empty.
  4. In August, the value of every current starter drops by 1. A player value never goes below 0.
  5. In November, rebuild the starters using rule 2.

Given NN players with their positions and values, the team is rebuilt with the process above in each year 1,2,⋯ ,K1, 2, \cdots, K. Find the sum of the starter values of the team formed in December of year KK.

Input

The first line contains NN and KK separated by a space. (0≤N≤1 000 000;(0\leq N\leq 1\,000\,000; 1≤K≤50 000)1\leq K\leq 50\,000)

From the second line onward, each of the next NN lines contains the position PiP_{i} and the value WiW_{i} of the ii-th player, separated by a space. (1≤i≤N;(1 \leq i \leq N; 1≤Pi≤11;1\leq P_{i}\leq 11; 1≤Wi≤100 000)1\leq W_{i}\leq 100\,000)

All input values are integers.

Output

Print the sum of the starter values of the team formed in December of year KK.

Examples1

  1. Example 1

    Input
    11 1
    1 5
    2 4
    3 2
    4 3
    5 10
    6 9
    7 6
    8 8
    9 11
    10 5
    11 6
    
    Expected output
    58