/*
先分析题目,总共有四个等级,为了方便排序我根据不同等级增加了初始分。
使用了qsort快速排序。
不能使用cout,否则会超时。
*/
#include <stdio.h>
#include <stdlib.h>
using namespace std;
typedef struct Stu{
int userID;
int de_score;
int cai_score;
int total;
}Stu;
Stu stu_arr[100000];
int comp(const void *a,const void *b);
int main()
{
int number,Low,High;
scanf("%d%d%d",&number,&Low,&High);
for(int i = 0;i<number;i++)
{
scanf("%d%d%d",&stu_arr[i].userID,&stu_arr[i].de_score,&stu_arr[i].cai_score);
stu_arr[i].total = 0;
}
// Divide grade
for(int i = 0; i<number;i++)
{
// Grade A
if(stu_arr[i].de_score>=High && stu_arr[i].cai_score>=High)
stu_arr[i].total = 3000 + stu_arr[i].de_score + stu_arr[i].cai_score;
// Grade B
else if(stu_arr[i].de_score>=High && stu_arr[i].cai_score>=Low && stu_arr[i].cai_score<High )
stu_arr[i].total = 2000 + stu_arr[i].de_score + stu_arr[i].cai_score;
// Grade C
else if(stu_arr[i].de_score>=Low && stu_arr[i].de_score<High && stu_arr[i].cai_score>=Low && stu_arr[i].cai_score<High && stu_arr[i].de_score>=stu_arr[i].cai_score)
stu_arr[i].total = 1000 + stu_arr[i].de_score + stu_arr[i].cai_score;
// Grade D
else if(stu_arr[i].de_score>=Low && stu_arr[i].cai_score>=Low)
stu_arr[i].total = stu_arr[i].de_score + stu_arr[i].cai_score;
}
// AC counts
int counts = 0;
for(int i = 0; i<number;i++)
if(stu_arr[i].de_score>=Low && stu_arr[i].cai_score>=Low)
counts ++;
qsort(stu_arr,number,sizeof(Stu),comp);
// OUTPUT
printf("%d\n",counts);
int i = 0;
while(stu_arr[i].de_score>=Low && stu_arr[i].cai_score>=Low)
{
printf("%d %d %d\n",stu_arr[i].userID,stu_arr[i].de_score,stu_arr[i].cai_score);
i++;
}
return 0;
}
int comp(const void *a,const void *b)
{
Stu s1 = *(Stu*)a;
Stu s2 = *(Stu*)b;
if(s1.total != s2.total)
return s2.total - s1.total;
else if(s1.de_score != s2.de_score)
return s2.de_score - s1.de_score;
else
return s1.userID - s2.userID;
}