世界首富
https://www.acwing.com/problem/content/1543/
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 210;
int n, m;
struct Person
{
string name;
int age, w;
bool operator< (const Person& t) const
{
if (w != t.w) return w > t.w;
if (age != t.age) return age < t.age;
return name < t.name;
}
};
vector<Person> ages[N];
int idx[N];
int main()
{
scanf("%d%d", &n, &m);
char name[10];
for (int i = 0; i < n; i ++ )
{
int age, w;
scanf("%s%d%d", name, &age, &w);
ages[age].push_back({name, age, w});
}
for (auto& age : ages) sort(age.begin(), age.end());
for (int C = 1; C <= m; C ++ )
{
printf("Case #%d:\n", C);
int cnt, a, b;
scanf("%d%d%d", &cnt, &a, &b);
memset(idx, 0, sizeof idx);
bool exists = false;
while (cnt -- )
{
int t = -1;
for (int i = a; i <= b; i ++ )
if (idx[i] < ages[i].size())
{
if (t == -1 || ages[i][idx[i]] < ages[t][idx[t]])
t = i;
}
if (t == -1) break;
auto& p = ages[t][idx[t]];
idx[t] ++ ;
printf("%s %d %d\n", p.name.c_str(), p.age, p.w);
exists = true;
}
if (!exists) puts("None");
}
return 0;
}