View Code of Problem 5

#include <stdio.h>
int main(){
	int t;
	scanf("%d",&t);
	while(t>0){
		int n;int m;
		scanf("%d %d",&n,&m);
			
		int apple[100];
		int pear[100];
		int selet[10];
		
		for(int i=0;i<n;i++){
			scanf("%d %d",&apple[i],&pear[i]);
		}
		
		for(int j = 0; j<m ; j++){
			int max = 0;
			for(int k = 0; k<n ; k++){
		     	if(apple[k]>apple[max])	max = k;
			    if(apple[k] == apple[max]){
			       if(pear[k]>apple[max])
			          max = k;
					  }else if(pear[k] == apple[max]){
  						if(k < max)max = k;
  					} 	
			}
			printf("%d ",max+1);
			apple[max] = 0;
			pear [max] = 0;
		}
		t--;
	}
}

Double click to view unformatted code.


Back to problem 5