View Code of Problem 5

#include <stdio.h>
int main()
{
	int a[100000][2],t,i,j,n,m,k,p;
	printf("input t(t<=10):\n");
	scanf("%d",&t);
	for(i=0;i<t;i++)
	{
		printf("input n and m(n>m):");
	    scanf("%d %d",&n,&m);
		printf("input a and b:\n");
		for(j=0;j<n;j++)
		{
			scanf("%d %d",&a[j][0],&a[j][1]);
		}
		for(j=0;j<m;j++)
		{
			p=0;
		    for(k=1;k<n;k++)
			{
				
			    if(a[p][0]<a[k][0])
			         p=k;
		    	    if(a[k][0]==a[p][0]&&a[k][1]>a[p][1])
                                 p=k;
			}
			printf("%d\n",p+1);
			a[p][0]=0;
			if(i<m-1)
				printf("  ");
		}
	}
}
	

Double click to view unformatted code.


Back to problem 5