View Code of Problem 5

#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

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

Double click to view unformatted code.


Back to problem 5