View Code of Problem 5

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

		

Double click to view unformatted code.


Back to problem 5