1 #include<iostream>
2 #include<vector>
3 #include<algorithm>
4 #include<cmath>
5 #include<cstdio>
6 using namespace std;
7 struct student{
8 int score;
9 char team;
10 int sum;
11 };
12 vector<student> vec;
13 vector<vector<int> > mark_team(30);
14 vector<int> project(30);
15 bool cmp(student a, student b){
16 if (a.sum != b.sum)
17 return a.sum>b.sum;
18 else
19 return a.team<b.team;
20 }
21 int main(){
22 struct student stu;
23 int n, k;
24 char c;
25 scanf("%d%d", &n, &k);
26 for (int i = 0; i<n; i++){
27 scanf("%d %c", &stu.score, &stu.team);
28 vec.push_back(stu);
29 }
30 for (int i = 0; i<30; i++){
31 mark_team[i].resize(30);
32 }
33 int a;
34 for (int i = 0; i<k; i++){
35 for (int j = 0; j<k; j++){
36 scanf("%d", &a);
37 mark_team[i][j] = a;
38 }
39 }
40 double sum;
41 int count;
42 for (int j = 0; j<k; j++){
43 sum = 0;
44 count = 0;
45 for (int i = 0; i<k; i++){
46 sum += mark_team[i][j];
47 }
48 double average = sum / k;
49 sum = 0;
50 for (int i = 0; i<k; i++){
51 if (abs(mark_team[i][j] - average) <= 15){
52 sum += mark_team[i][j];
53 count++;
54 }
55 }
56 average = sum / count;
57 project[j] = round(average);
58 }
59 for (int i = 0; i<n; i++){
60 vec[i].sum =round( vec[i].score*0.6 + project[vec[i].team - 'A'] * 0.4);
61 }
62 sort(vec.begin(), vec.end(), cmp);
63 for (int i = 0; i<n; i++){
64 printf("%d %c
", vec[i].sum, vec[i].team);
65 }
66 return 0;
67 }