Under construction

Still being built. Things may change

Selecting the Ten Best Teachers

Time limit1sMemory limit128 MB

Summary
Tally valid ballots into weighted place scores and print the top ten teachers with vote breakdowns in fixed-width columns.
Level

Easy3 of 10

Topics
Simulation, Sorting, Implementation
Solved
No attempts yet

Problem

A school picks its ten best teachers out of nn teachers (n≤50n \le 50) by a secret ballot among the students.

The teachers are numbered continuously starting at 1, and every number is written with two characters: 01, 02, 03 and so on.

One ballot lists the numbers of ten selected teachers. The position a number sits in is the place that ballot gives the teacher. A place may be left empty, and an empty place is written as 00. A ballot is discarded when it holds a number outside the range 01 to nn, or when the same teacher number appears twice or more. The empty marker 00 may repeat as often as it likes and never discards a ballot.

Each place carries a score.

PlaceFirstSecondThirdFourthFifthSixthSeventhEighthNinthTenth
Score151297654321

The vote count of a teacher is the number of accepted ballots that write that teacher into a place other than an empty one. Sort the teachers by total score, from high to low. Two teachers on the same score are ordered by vote count, the larger one first. When the score and the vote count are both equal, the smaller teacher number comes first.

Input

The first line holds two integers nn and mm separated by a space: the number of teachers and the number of ballots.

Each of the next nn lines describes one teacher as a number, a name, and a department, separated by single spaces. The teacher lines may arrive in any order, and no name or department contains a space. Names are at most 15 characters long and departments at most 37.

Each of the next mm lines holds one ballot, a string of exactly 20 characters made of ten two-digit numbers.

The last line is -1.

Output

Print the first min⁡(n,10)\min(n, 10) teachers of the sorted order, one per line. Each line joins the following fields with no separator between them.

  • the rank, counted from 1, left aligned in 4 columns
  • the two-digit teacher number, left aligned in 4 columns
  • the name, left aligned in 15 columns
  • the department, left aligned in 37 columns
  • twelve integers, each right aligned in 6 columns, in this order: the total score, the vote count, then how many first places the teacher took, how many second places, and so on down to how many tenth places

A field shorter than its width is padded with spaces, so every printed line is 132 characters long.

Examples1

  1. Example 1

    Input
    15 30
    08 Christopher Power&EnergyEngineering
    02 Amanda MaterialsScience&Engineering
    13 Matthew Chemistry&ChemicalTechnology
    15 Sarah LifeScience&Biotechnology
    05 Joshua Power&EnergyEngineering
    06 Brittany ElectricPowerEngineering
    07 Andrew HumanitiesandSocialScience
    01 Megan MaterialsScience&Engineering
    09 Daniel Management
    04 Jennifer CivilEngineering&Mechanics
    03 Justin Electronics&InformationTechnology
    12 Nicole Chemistry&ChemicalTechnology
    10 David Power&EnergyEngineering
    14 Stephanie Chemistry&ChemicalTechnology
    11 Ryan LifeScience&Biotechnology
    01060503130412020009
    07020905071308081015
    01000000000000000000
    00000200000112000006
    12031301110402071306
    15021413091211100603
    15110314030406011412
    03011110030312120114
    08010409140206120513
    08121206020601141214
    11131506040914021402
    05040711140506041413
    09020204011009120214
    07050613151209040414
    10010410030309040514
    11090113111114090110
    06100307030808131510
    09131505030801150611
    15060509120610100111
    11030613130909050701
    12130409091402121402
    03111411041508110909
    01130112061109090408
    12140507060809151314
    12150811060915040702
    11130607071007111408
    12050714010205071214
    09030603090108101313
    15040615061107020608
    02050202111309080506
    -1
    
    Expected output
    1   01  Megan          MaterialsScience&Engineering             47     4     2     1     0     0     0     1     0     0     0     0
    2   02  Amanda         MaterialsScience&Engineering             29     4     0     1     1     0     0     1     0     1     0     0
    3   06  Brittany       ElectricPowerEngineering                 19     4     0     1     0     0     0     0     1     0     1     1
    4   12  Nicole         Chemistry&ChemicalTechnology             16     4     0     0     0     0     0     1     2     1     0     0
    5   14  Stephanie      Chemistry&ChemicalTechnology             15     2     0     0     1     0     1     0     0     0     0     0
    6   08  Christopher    Power&EnergyEngineering                  15     1     1     0     0     0     0     0     0     0     0     0
    7   15  Sarah          LifeScience&Biotechnology                15     1     1     0     0     0     0     0     0     0     0     0
    8   09  Daniel         Management                               14     3     0     0     0     1     1     0     0     0     0     1
    9   13  Matthew        Chemistry&ChemicalTechnology             14     3     0     0     0     1     1     0     0     0     0     1
    10  04  Jennifer       CivilEngineering&Mechanics               14     2     0     0     1     0     0     1     0     0     0     0