80分,两个测试点WA(着急呜呜)
查看原帖
80分,两个测试点WA(着急呜呜)
335679
85180220st楼主2020/8/15 13:32
#include<bits/stdc++.h>
using namespace std;
const int N = 5e6 + 1;
int a[N];
struct Student {
	int id;
	int score;
};
Student stu[N];
bool cmp(Student a, Student b) {
	return a.score == b.score ? a.id<b.id : a.score>b.score;
}
int main()
{
	int n, m, i, k, min = INT_MIN, cnt = 0;
	cin >> n >> m;
	for (i = 0; i < n; i++) {
		cin >> stu[i].id >> stu[i].score;
	}
	sort(stu, stu + n, cmp);
	k = floor(m * 1.5);//向下取整
	for (i = 0; i < n; i++) {//计算录取人数
		if (stu[i].score >= stu[k - 1].score)
			cnt++;
		else
			break;
	}
	cout << stu[k].score << " " << cnt << endl;
	for (i = 0; i < n; i++) {
		if (stu[i].score >= stu[k - 1].score)
			cout << stu[i].id << " " << stu[i].score << endl;
	}
	return 0;
}
2020/8/15 13:32
加载中...