View Code of Problem 5

#include <stdio.h>
#include <string.h>
#include <math.h>
struct sg{
	int id;
	int app;
	int pear;
	
};


int main(){
	int t;
	int n,m;
	int i,j;
	scanf("%d",&t);
	while(t--){
		scanf("%d %d",&n,&m);
		struct sg list[n],temp;
		for(i=0;i<n;i++){
			scanf("%d %d",&list[i].app,&list[i].pear);
			list[i].id=i+1;
		}
		for(i=0;i<n-1;i++){
			for(j=0;j<n-i-1;j++){
				if(list[j].pear<list[j+1].pear){
					temp=list[j];
					list[j]=list[j+1];
					list[j+1]=temp;
				}
			}
		}
	for(i=0;i<n-1;i++){
			for(j=0;j<n-i-1;j++){
				if(list[j].app<list[j+1].app){
					temp=list[j];
					list[j]=list[j+1];
					list[j+1]=temp;
				}
			}
		}
		
		for(i=0;i<m-1;i++){
			printf("%d ",list[i].id);
		}
          printf("%d",list[i].id);
		printf("\n");
		
		
		
		
		
		
	} 
} 

Double click to view unformatted code.


Back to problem 5