#include"bits/stdc++.h"
using namespace std;
char table[1000006];
struct stud{
int C, M, E;
double A;
stud(){}
stud(int c, int m, int e, double a){
C = c;
M = m;
E = e;
A = a;
}
};
struct node{
char subject;
int rank;
node(char a, int b){
rank = b;
subject = a;
}
};
int getpri(char p){
if(p == 'A') return 1;
if(p == 'C') return 2;
if(p == 'M') return 3;
if(p == 'E') return 4;
return 5;
}
bool cmp(node a, node b){
if(a.rank != b.rank) return a.rank < b.rank;
else return getpri(a.subject) < getpri(b.subject);
}
map<int, stud> mp;
vector<int> Cv, Mv, Ev;
vector<double> Av;
int main(){
memset(table, 0, 1000006);
int n, checkn;
scanf("%d %d", &n, &checkn);
for(int i = 0; i < n; ++i){
int tempid, tempc, tempm, tempe;
double tempa;
scanf("%d %d %d %d", &tempid, &tempc, &tempm, &tempe);
tempa = (tempc + tempm + tempe) / 3.;
Av.push_back(tempa);
Cv.push_back(tempc);
Mv.push_back(tempm);
Ev.push_back(tempe);
mp[tempid] = stud(tempc, tempm, tempe, tempa);
table[tempid] = -1;
}
sort(Av.begin(), Av.end());
sort(Cv.begin(), Cv.end());
sort(Mv.begin(), Mv.end());
sort(Ev.begin(), Ev.end());
for(int i = 0; i < checkn; ++i){
int tempid;
scanf("%d", &tempid);
if(!table[tempid]){
printf("N/A\n");
continue;
}
stud s = mp[tempid];
vector<node> v;
v.push_back(node('A', 1 + n - (upper_bound(Av.begin(), Av.end(), s.A) - Av.begin())));
// 注意:不能使用n - (lower_bound(Av.begin(), Av.end(), s.A) - Av.begin()),这是因为存在并列。
v.push_back(node('C', 1 + n - (upper_bound(Cv.begin(), Cv.end(), s.C) - Cv.begin())));
v.push_back(node('M', 1 + n - (upper_bound(Mv.begin(), Mv.end(), s.M) - Mv.begin())));
v.push_back(node('E', 1 + n - (upper_bound(Ev.begin(), Ev.end(), s.E) - Ev.begin())));
sort(v.begin(), v.begin() + 4, cmp);
printf("%d %c\n", v[0].rank, v[0].subject);
}
}
1012 The Best Rank (25 分)(简单Sort)
最新推荐文章于 2024-11-18 18:10:05 发布