View Code of Problem 5

#include<stdio.h>
#include <string.h>
#include <math.h>
void main()
{
   int n,i,j,k,p,q,max=0,a[1000],b[1000];
   scanf("%d",&n);
   while(n--)
   {
	   scanf("%d%d",&p,&q);
	   max=0;
	   for(i=0;i<p;i++)
	   {
		   scanf("%d%d",&a[i],&b[i]);
	   }
	   for(j=0;j<q;j++)
	   {
	   for(i=0;i<p;i++)
	   {
		   if(a[max]<a[i]||a[max]==a[i]&&b[max]<b[i])
			   max=i;
	   }
	   if(j==q-1)
	   printf("%d\n",max+1);
	   else
		    printf("%d ",max+1);
	   a[max]=0;
	   b[max]=0;
	   }


   }
    
}

Double click to view unformatted code.


Back to problem 5