View Code of Problem 5

#include<bits/stdc++.h>
using namespace std;
int t, n, m;
struct node {
	int id, x, y;
}a[100005];
bool cmp(struct node n1, struct node n2) {
	if (n1.x != n2.x)
		return n1.x > n2.x;
	if (n1.y != n2.y)
		return n1.y > n2.y;
	return n1.id < n2.id;
}
int main() {
	cin >> t;
	while (t--) {
		cin >> n >> m;
		for (int i = 1; i <= n; i++) {
			cin >> a[i].x >> a[i].y;
			a[i].id = i;
		}
		sort(a + 1, a + n + 1, cmp);
		for (int i = 1; i <= m; i++) {
			if (i == 1)
				cout << a[i].id;
			else
				cout<<" "<< a[i].id;
		}
		cout << endl;
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 5