AcWing 1541. 世界首富
原题链接
中等
作者:
RainSure
,
2022-02-23 20:33:21
,
所有人可见
,
阅读 240
多路归并
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn = 210;
typedef struct node
{
string name;
int age, w;
bool operator < (const struct node &m) const{
if(w != m.w) return w > m.w;
if(age != m.age) return age < m.age;
return name < m.name;
}
}Node;
int n, m;
int num[maxn];
vector<Node> ages[maxn];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for(int i = 0; i < n; i ++){
string name;
int age, w;
cin >> 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 ++){
cout << "Case #" << C << ":" << endl;
int cnt, a, b; cin >> cnt >> a >> b;
memset(num, 0, sizeof num);
bool flag = false;
while(cnt --){
int t = -1;
for(int i = a; i <= b; i ++){
if(num[i] < ages[i].size()){
if(t == -1 || ages[i][num[i]] < ages[t][num[t]]){
t = i;
}
}
}
if(t == -1) break;
auto p = ages[t][num[t]];
num[t] ++;
cout << p.name << " " << p.age << " " << p.w << endl;
flag = true;
}
if(!flag) cout << "None" << endl;
}
return 0;
}