View Code of Problem 5

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

	return 0;
}

Double click to view unformatted code.


Back to problem 5