View Code of Problem 5

#include <stdio.h>
#include <string.h>
int main(){
	int a[1000],m,n,t,i,j;
	scanf("%d",&t);
	while(t--){
		scanf("%d %d",&n,&m);
		for(i=0;i<n;i++){
			int a1,b;
			scanf("%d %d",&a1,&b);
			a[i]=a1*100000+b;
		}
		for(i=0;i<n;i++){
			int max=0;
			for(j=0;j<m;j++){
				if(a[j]>max)
				max=a[j];
			}
			if(i==0) printf("%d",max+1);
		    else printf(" %d",max+1);
		    a[max]=-1;
		}
		printf("\n");
	}

}

Double click to view unformatted code.


Back to problem 5