Save BPL

whoisshihab Programming Contest for F...
Limits 1s, 512 MB

Bangladesh Premier League (BPL) is one the most prestigious cricket tournaments. Talented players from different countries gather here to show off their talents, share knowledge.
But BPL committee is facing some difficulties in selecting teams, making budgets etc. They spend a few crores in buying softwares. But for a specific job, they need your help.
There are N teams (0< N <= 50000).
Each team primarily selects up-to M players (15 <= M <= 2000).

The lists of primarily-selected players consist of English alphabets of small letters ('a' to 'z').
Each letter means the cost for a player. Where 'a' is the lowest and 'z' is the highest. Where value of 'a' is 1, value of 'b' is 2 ... value of 'z' is 26.

There is no way to select players of the lowest prices randomly.
All players are standing in a circular shape.
You have to select a part from that which will be the lexicographically smallest, consisting 15 players for each team.
The final cost for a team is sum of the values of all 15 players.
Getting a list of players whose value is lexicographically smallest, is the number 1 goal of franchises.

You are given N teams, find out how much money in total is going to be spent to buy teams.


First line of the input will be N(Number of Teams) then N lines follow. Each line contains the primarily selected players.


Output the total cost of all the franchises.




Login to submit.


62% Solution Ratio
MIST_LastTryEarliest, Aug '17
SIR.24Fastest, 0.1s
MIST_LastTryLightest, 131 kB
wasimur_01Shortest, 479B
Toph uses cookies. By continuing you agree to our Cookie Policy.