q
2025-04-18 17:49:21
发布于:内蒙古
0阅读
0回复
0点赞
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
// 定义结构体存储选手信息
struct Student {
int id;
int score;
};
// 比较函数,用于排序
bool compare(const Student& a, const Student& b) {
if (a.score != b.score) {
return a.score > b.score;
}
return a.id < b.id;
}
int main() {
int n, m;
cin >> n >> m;
vector<Student> students(n);
for (int i = 0; i < n; ++i) {
cin >> students[i].id >> students[i].score;
}
// 对选手信息进行排序
sort(students.begin(), students.end(), compare);
// 计算面试分数线的索引
int limit = int(m * 1.5);
int line = students[limit - 1].score;
// 统计进入面试的人数
int count = 0;
for (const auto& student : students) {
if (student.score >= line) {
count++;
}
}
cout << line << " " << count << endl;
// 输出进入面试的选手信息
for (const auto& student : students) {
if (student.score >= line) {
cout << student.id << " " << student.score << endl;
}
}
return 0;
}
这里空空如也
有帮助,赞一个