Result: Accepted
Time: 682ms
Memory: 2048kB
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
struct student
{
int name;
int l,h;
};
vector <struct student> v1;
vector <struct student> v2;
vector <struct student> v3;
vector <struct student> v4;
int n,L,H;
bool cmp1(struct student p,struct student q)
{
if ((p.l+p.h) != (q.l+q.h))
return (p.l+p.h) > (q.l+q.h);
else if (p.l!=q.l)
return p.l > q.l;
else
return p.name<q.name;
}
int main()
{
int N=0;
cin >> n >> L >> H;
for (int i=0;i<n;i++)
{
struct student tmp;
cin >> tmp.name >> tmp.l >> tmp.h;
if (tmp.l<L||tmp.h<L)
{
N++;
continue;
}
else if(tmp.l>=H&&tmp.h>=H)
{
v1.push_back(tmp);
}
else if(tmp.l>=H&&tmp.h<H)
{
v2.push_back(tmp);
}
else if(tmp.l>=tmp.h)
{
v3.push_back(tmp);
}
else
{
v4.push_back(tmp);
}
}
cout << n-N << endl;
sort(v1.begin(),v1.end(),cmp1);
sort(v2.begin(),v2.end(),cmp1);
sort(v3.begin(),v3.end(),cmp1);
sort(v4.begin(),v4.end(),cmp1);
for (int i=0;i<v1.size();i++)
cout << v1[i].name <<" "<< v1[i].l <<" "<< v1[i].h << endl;
for (int i=0;i<v2.size();i++)
cout << v2[i].name <<" "<< v2[i].l <<" "<< v2[i].h << endl;
for (int i=0;i<v3.size();i++)
cout << v3[i].name <<" "<< v3[i].l <<" "<< v3[i].h << endl;
for (int i=0;i<v4.size();i++)
cout << v4[i].name <<" "<< v4[i].l <<" "<< v4[i].h << endl;
}