代码:
#include<cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
//N<=40000,M<=100,k<=5
int now;
struct Stu {
int ge, gi, g;
int sch[6];
int rank, id;
};
struct Sch {
int quota;
int admit[40005];
int na;
int lastone;
};
Sch school[105];
Stu stu[40005];
bool cmp(Stu a, Stu b) {
if (a.g != b.g)return a.g > b.g;
else if (a.ge != b.ge)return a.ge > b.ge;
else return a.id < b.id;
}
bool cmp2(int a, int b) {
return a < b;
}
int main() {
int n, m, k;
scanf("%d %d %d", &n, &m, &k);
for (int i = 0; i < m; i++) {
scanf("%d", &school[i].quota);
school[i].na = 0;
school[i].lastone = -1;
}
for (int i = 0; i < n; i++) {
stu[i].id = i;
scanf("%d %d", &stu[i].ge, &stu[i].gi);
for (int j = 0; j < k; j++) {
scanf("%d", &stu[i].sch[j]);
}
stu[i].g = stu[i].ge + stu[i].gi;
}
sort(stu, stu + n, cmp);
//排名
for (int i = 0; i < n; i++) {
if (i == 0)stu[i].rank = 1;
else if (stu[i].g == stu[i - 1].g&&stu[i].ge == stu[i - 1].ge)
stu[i].rank = stu[i - 1].rank;
else stu[i].rank = i + 1;
}
//录取工作
for (int i = 0; i < n; i++) {
int s,lastone;
for (int j = 0; j < k; j++) {
s = stu[i].sch[j];
lastone = school[s].lastone;
if (school[s].quota != 0) {
school[s].quota--;
school[s].admit[school[s].na++] = stu[i].id;
school[s].lastone = i;
break;
}
else if (lastone != -1&& stu[i].rank == stu[lastone].rank) {
school[s].admit[school[s].na++] = stu[i].id;
school[s].lastone = i;
break;
}
}
}
//输出
for (int i = 0; i < m; i++) {
if (school[i].na){
int na = school[i].na;
sort(school[i].admit, school[i].admit + na, cmp2);
for (int j = 0; j < na; j++) {
if (j == 0) {
printf("%d", school[i].admit[j]);
}
else {
printf(" %d", school[i].admit[j]);
}
}
}
printf("\n");
}
return 0;
}