-
Notifications
You must be signed in to change notification settings - Fork 0
/
1055_The_Worlds_Richest.cpp
51 lines (46 loc) · 1.25 KB
/
1055_The_Worlds_Richest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <bits/stdc++.h>
using namespace std;
struct People {
char name[10];
int age;
int netWorth;
};
bool cmp(People a, People b) {
if (a.netWorth != b.netWorth)
return a.netWorth > b.netWorth;
else if (a.age != b.age)
return a.age < b.age;
else
return (strcmp(a.name, b.name) < 0);
}
int main() {
int n, k;
scanf("%d%d", &n, &k);
vector<People> v(n);
for (int i = 0; i < n; ++i)
scanf("%s%d%d", v[i].name, &v[i].age, &v[i].netWorth);
sort(v.begin(), v.end(), cmp);
vector<People> temp;
vector<int> nums(205, 0);
for (int i = 0; i < n; ++i) {
if (nums[v[i].age] < 100) {
temp.push_back(v[i]);
nums[v[i].age]++;
}
}
int m, Amin, Amax, cnt = 1;
while (cnt <= k) {
scanf("%d%d%d", &m, &Amin, &Amax);
vector<People> res;
for (int i = 0; i < temp.size(); ++i) {
if (temp[i].age >= Amin && temp[i].age <= Amax)
res.push_back(temp[i]);
}
printf("Case #%d:\n", cnt++);
for (int i = 0; i < res.size() && i < m; ++i) {
printf("%s %d %d\n", res[i].name, res[i].age, res[i].netWorth);
}
if (res.empty()) printf("None\n");
}
return 0;
}