View Code of Problem 5

#include<stdio.h>
int main()
{
	int t;
	scanf("%d", &t);
	while (t--)
	{
		int n, m, a[100000][2], b[100000], i, j, temp,t,T;
		scanf("%d%d", &n, &m);
		for (i = 0;i<n;i++)
		{
			scanf("%d%d", &a[i][0], &a[i][1]);
			b[i] = i + 1;
		}
		for (i = 0;i<n;i++)
		{
			for (j = i + 1;j<n;j++)
			{
				if (a[i][0] * 100000 + a[i][1]<a[j][0] * 100000 + a[j][1])
				{
					temp = a[i][0];a[i][0] = a[j][0];a[j][0] = temp;
					t = a[i][1];a[i][1] = a[j][1];a[j][1] = t;
					T = b[i];b[i] = b[j];b[j] = T;
				}
			}
		}
		for (i = 0;i<m - 1;i++)
			printf("%d ", b[i]);
		printf("%d\n", b[m - 1]);
	}
}

Double click to view unformatted code.


Back to problem 5