题目传送门
#include <iostream> #include <algorithm> #include <vector> using namespace std; struct node { int num, de, cai; }; int cmp(struct node a, struct node b) { if ((a.de + a.cai) != (b.de + b.cai)) { return (a.de + a.cai) > (b.de + b.cai); } else if (a.de != b.de) { return a.de > b.de; } else { return a.num < b.num; } } int main() { int n, low, high; cin >> n >> low >> high; vector<node> v[4]; node temp; int total = n; for (int i = 0; i < n; i++) { cin >> temp.num >> temp.de >> temp.cai; if (temp.de < low || temp.cai < low) { total--; } else if (temp.de >= high && temp.cai >= high) { v[0].push_back(temp); } else if (temp.de >= high && temp.cai < high) { v[1].push_back(temp); } else if (temp.de < high && temp.cai < high && temp.de >= temp.cai) { v[2].push_back(temp); } else { v[3].push_back(temp); } } cout << total << endl; for (int i = 0; i < 4; i++) { sort(v[i].begin(), v[i].end(), cmp); for (int j = 0; j < v[i].size(); j++) { cout << v[i][j].num << " " << v[i][j].de << " " << v[i][j].cai << endl; } } return 0; }