View Code of Problem 5

#include<bits/stdc++.h>
using namespace std;
 
 
struct lanzi {
	int id;
	int apple;
	int pear;
}l[100001];
 
 
int cmp(lanzi a, lanzi b) {
	if (a.apple == b.apple) {
		if (a.pear == b.pear) {
			return a.id < b.id;
		}else {
			return a.pear > b.pear;
		}
	}else {
		return a.apple>b.apple;
	}
}
int main() {
	int t;
	cin >> t;
	while (t--) {
		int n, m;
		cin >> n >> m;
		for (int i = 1; i <= n; i++) {
			cin >> l[i].apple >> l[i].pear;
			l[i].id = i;
		}
		sort(l+1, l + n+1, cmp);
		for (int i = 1; i <= m; i++) {
			if (i != m) {
				cout << l[i].id << " ";
			}
			else {
				cout << l[i].id;
			}
		}
		cout <<endl;
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 5