#RT,先上代码
#include <bits/stdc++.h>
using namespace std;
struct dat
{
int ord; // ord == order
int mar; // mar == mark
};
void countingSort(dat[], int);
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
dat data[n];
for(int i = 0; i < n; i ++) cin >> data[i].ord >> data[i].mar;
countingSort(data, n); // 计数排序
int num = (int)(m*1.5);//划定分数线,下一行是判断下一个人的分数,若相同则人数num自加.
while(data[n-num-1].mar == data[n-(int)(m*1.5)].mar) num++;
cout << data[n-num].mar << " " << num << endl;
for(int i = n-1; i >= n-num; i --)
cout << data[i].ord << " " << data[i].mar << endl;
return 0;
}
void countingSort(dat arr[], int len)
{
int count[101] = {0};
dat temp[len]; // 我的上帝啊,我发誓这里不会有什么问题的.
for(int i = 0; i < len; i ++) count[arr[i].mar] ++;
for(int i = 1; i <= 100; i ++) count[i] += count[i-1];
for(int i = len-1; i >= 0; i --) temp[count[arr[i].mar]-- -1] = arr[i];
for(int i = 0; i < len; i ++) arr[i] = temp[i];
return;
}
最初是自定义比较函数用sort做了,后来以为是sort的问题就换成了计数排序.然而只有#2点AC了,其他全WA.顺便贴上#1返回数据: in: 6 3 9848 90 6731 88 1422 95 7483 84 8805 95 4162 88
out: 88 5 1422 95 8805 95 9848 90 4162 88 6731 88
#多谢诸佬