View Code of Problem 5

#include<stdio.h>
#include<string.h>
#include<math.h>

struct p{
	int a;
	int b;
	int c;		
}c[10];

int main()
{
		int a;
		int b[10][10];
		scanf("%d",&a);
		for(int i=0;i<a;i++){

			int n,m;
			scanf("%d%d",&n,&m);
			
			for(int j=0;j<n;j++)
			{scanf("%d%d",&c[j].b,&c[j].c);c[j].a=j;}
			
			
			for(int k=0;k<m;k++)
			{
				int max=0;
				for(int l=1;l<n;l++)
				{
					if(c[l].b>c[max].b)max=l;
					if(c[l].b==c[max].b&&c[l].c>c[max].c)max=l;
				}
				if(k!=m-1)printf("%d ",max+1);
				else printf("%d",max+1);
				c[max].b=-1;
			}
		
		}
}

Double click to view unformatted code.


Back to problem 5