View Code of Problem 5

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

void getMax(int arr[][3],int n,int m){
	int i,j,sort[100000];
	for(i = 0; i < n; i ++){
		int fmax = arr[i][0];
		int smax = arr[i][1];
		int max = i;
		for(j = i+1; j < n; j ++){
			if(fmax == arr[j][0]){
				if(smax < arr[j][1] ){
					max = j;
				}
			}else if(fmax < arr[j][0]){
				max = j;
			}
		}
		sort[i] = arr[max][2];
		if(max != i){
			int t1 = arr[i][0];
			int t2 = arr[i][1];
			int t3 = arr[i][2];
			arr[i][0] = arr[max][0];
			arr[i][1] = arr[max][1];
			arr[i][2] = arr[max][2];
			arr[max][0] = t1;
			arr[max][1] = t2;
			arr[max][2] = t3;
		}
	}
	for(i = 0; i < m; i ++){
		if(i == m-1){
			printf("%d\n",sort[i]);
		}else{
			printf("%d ",sort[i]);
		}
	}
}

int main(){
	
	int t,i,j;
	int arr[100000][3];
	scanf("%d",&t);
	for(i=0; i < t; i ++){
		int n,m;
		scanf("%d%d",&n,&m);
		for(j = 0; j < n; j ++){
			scanf("%d%d",&arr[j][0],&arr[j][1]);
			arr[j][2] = j+1;
		}
		getMax(arr,n,m);
	}
	
	return 0;
}

Double click to view unformatted code.


Back to problem 5