题解
2024-11-07 23:14:29
发布于:浙江
2阅读
0回复
0点赞
#include <iostream>
#include <vector>
#include <algorithm>
struct Candidate {
int id;
int score;
};
// Custom comparator to sort by score in descending order, then by id in ascending order if scores are the same
bool compare(const Candidate &a, const Candidate &b) {
if (a.score != b.score)
return a.score > b.score;
return a.id < b.id;
}
int main() {
int n, m;
std::cin >> n >> m;
std::vector<Candidate> candidates(n);
// Reading the candidate data
for (int i = 0; i < n; ++i) {
std::cin >> candidates[i].id >> candidates[i].score;
}
// Sort candidates by score (descending) and by id (ascending) if scores are the same
std::sort(candidates.begin(), candidates.end(), compare);
// Calculate the interview threshold rank
int thresholdRank = static_cast<int>(m * 1.5); // m * 150% and take the floor
// Determine the threshold score based on the sorted list
int interviewScoreLine = candidates[thresholdRank - 1].score;
// Collect all candidates who meet or exceed the threshold score
std::vector<Candidate> qualifiedCandidates;
for (const auto &candidate : candidates) {
if (candidate.score >= interviewScoreLine) {
qualifiedCandidates.push_back(candidate);
}
}
// Output the results
std::cout << interviewScoreLine << " " << qualifiedCandidates.size() << std::endl;
for (const auto &candidate : qualifiedCandidates) {
std::cout << candidate.id << " " << candidate.score << std::endl;
}
return 0;
}
全部评论 1
AI 大法好
6天前 来自 美国
0
有帮助,赞一个