#include <cmath>
#include <vector>
#include <climits>
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
using namespace std;
class People {
public:
int id;
int virtue;
int talent;
int totalGrade;
int flag = -1; // 4-sage;3-noble;2-fool;1-small;
};
bool compare1062(People p1, People p2) {
if (p1.flag == p2.flag) {
if (p1.totalGrade == p2.totalGrade) {
if (p1.virtue == p2.virtue) {
return p1.id < p2.id;
}
else {
return p1.virtue > p2.virtue;
}
}
else {
return p1.totalGrade > p2.totalGrade;
}
}
else {
return p1.flag > p2.flag;
}
}
int main() {
int N, L, H;
cin >> N >> L >> H;
vector<People> checklist;
while (N--) {
People people;
scanf("%d %d %d", &people.id, &people.virtue, &people.talent);
people.totalGrade = people.virtue + people.talent;
// those with both grades not below this line are considered as the "sages", and will be ranked in non-increasing order according to their total grades
if (people.virtue >= H && people.talent >= H) {
people.flag = 4; // sage
}
// Those with talent grades below H but virtue grades not are cosidered as the "noblemen", and are also ranked in non-increasing order according to their total grades, but they are listed after the "sages"
else if (people.virtue >= H && people.talent < H && people.talent >= L) {
people.flag = 3; // noble
}
// Those with both grades below H, but with virtue not lower than talent are considered as the "fool men"
else if (people.virtue < H && people.virtue >= L && people.talent < H && people.talent >= L && people.virtue >= people.talent) {
people.flag = 2; // fool
}
else if (people.virtue >= L && people.talent >= L) {
// The rest of people whose grades both pass the L line are ranked after the "fool men".
people.flag = 1; // small
}
else {
// only the ones whose grades of talent and virtue are both not below this line will be ranked
}
if (people.flag > 0) checklist.push_back(people);
}
sort(checklist.begin(), checklist.end(), compare1062);
cout << checklist.size() << endl;
for (int i = 0; i < checklist.size(); i++) {
printf("%d %d %d\n", checklist[i].id, checklist[i].virtue, checklist[i].talent);
}
return 0;
}
网友评论