题解
2023-08-21 10:51:04
发布于:广东
4阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
struct w {
string name;
int atk;
int pri;
bool operator<(w other) const {
if (atk == other.atk) {
return pri < other.pri;
}
return atk > other.atk;
}
};
int main() {
int n, k;
cin >> n >> k;
vector<w> weapons(n);
for (int i = 0; i < n; ++i) {
cin >> weapons[i].name >> weapons[i].atk >> weapons[i].pri;
}
sort(weapons.begin(), weapons.end());
for (int i = 0; i < k; ++i) {
cout << weapons[i].name << endl;
}
return 0;
}
排个序,贪个心,搞定
这里空空如也
有帮助,赞一个