View Code of Problem 5

#include<stdio.h>
int Whichismax(int v[],int n) {
	int i,max;
	max = 0;
	for(i = 0; i < n; i ++)	{
		if(v[i] > v[max])
			max = i;
	}
	return max;
}
int main(void) {
	int i,t,n,m,a[100000][2],v[100000];
	scanf("%d",&t);
	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");
	}
}

Double click to view unformatted code.


Back to problem 5