算法
(冒泡排序) $O(n^2)$
开两个数组,一个数组存编号,另一个数组存成绩,然后用冒泡排序模拟一下就行了
C++ 代码
#include <iostream>
using namespace std;
const int N = 5010;
#define rep(i, n) for (i = 1; i <= n; i++)
int a[N], b[N];
int n, m;
int main() {
cin >> n >> m;
int i;
rep(i, n) cin >> a[i] >> b[i];
int j;
rep(i, n - 1) {
rep(j, n - i) {
if (b[j] < b[j + 1] || b[j] == b[j + 1] && a[j] > a[j + 1]) {
swap(a[j], a[j + 1]);
swap(b[j], b[j + 1]);
}
}
}
m *= 1.5;
cout << b[m];
int cnt = 0;
rep(i, n) {
if (b[i] >= b[m]) cnt++;
}
cout << " " << cnt << endl;
rep(i, cnt) cout << a[i] << " " << b[i] << endl;
return 0;
}