View Code of Problem 5

#include <stdio.h>
int main()
{
	int t,apple[10000],pear[10000];
	int i,j,max_num=0,m,n;
	scanf("%d",&t);
	while(t>0)
	{
		scanf("%d %d",&n,&m);
		for(i=0;i<n;i++)
		{
			scanf("%d %d",&apple[i],&pear[i]);
		}
			while(m>0)
			{
				//int max_num = 0;
				for(j=1;j<n;j++)
				{
					if(apple[j]>apple[max_num])
					  max_num = j;
					else if(apple[j] == apple[max_num])
					{
						if(pear[j]>pear[max_num])
						  max_num = j;
					}
				}
				if(m==1)
				  printf("%d",max_num+1);
				else
				  printf("%d ",max_num+1);
				apple[max_num] = 0;
				pear[max_num] = 0;
				max_num = 0;
				m--;
			}
	
		printf("\n");
		t--;
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 5