View Code of Problem 5

#include<stdio.h>
int main()
{
	
	int t;
	scanf("%d",&t);
	while(t>0)
	{
		int n,m;
		int app[100],orgin[100];
		scanf("%d%d",&n,&m);
		
		int i;
		for(i=0;i<n;i++)
			scanf("%d%d",&app[i],&orgin[i]);
		
		while(m>0)
		{
			int maxapp=0;
			for(i=0;i<n;i++)
			{
				if(app[i]>app[maxapp])
					maxapp=i;
				else if(app[i]==app[maxapp])
				{
					if(orgin[i]>orgin[maxapp])
						maxapp=i;
				}
			}
			
			if(m==1)
				printf("%d",maxapp+1);
			else
				printf("%d ",maxapp+1);
			
			app[maxapp]=0;
			orgin[maxapp]=0;
			
			m--;
		}
		printf("\n");
		
		
		
		
		
		
		t--;
	}
	
	
	
	return 0;
}

Double click to view unformatted code.


Back to problem 5