View Code of Problem 5

#include<stdio.h>
int main()
{
	int t;
	int n,m;
	int k=1;
	int a[1001][2];
	int max;
	scanf("%d",&t);
	for(int i=1;i<=t;i++)
	{	
		k=1;
		scanf("%d %d",&n,&m);
		for(int j=1;j<=n;j++)
		{
			scanf("%d %d",&a[j][0],&a[j][1]);
		}
		for(int g=1;g<=m;g++)
		{
			for(int j=1;j<=n;j++)
			{
				if(a[k][0]<a[j][0])k=j;
				if(a[k][0]==a[j][0]&&a[k][1]<a[j][1])k=j;			
			}	
			if(g!=m)printf("%d ",k);
			else printf("%d",k);			
			a[k][0]=-1; 
		}
		printf("\n");
	}
	return 0;
} 

Double click to view unformatted code.


Back to problem 5