View Code of Problem 5

#include<stdio.h>
#include<string.h>
int main(){ 
    int i,j,k,t,n,m,x,max,s[100000][2];
    scanf("%d",&t);
    for(i=0;i<t;i++){
    	scanf("%d%d",&n,&m);
    	for(j=0;j<n;j++)
    		scanf("%d%d",&s[j][0],&s[j][1]);
    	
    	for(k=0;k<m;k++){
    		max=s[0][0];
    		x=0;
    		for(j=0;j<n;j++){
    		
    		if(s[j][0]>max){
    			max=s[j][0];
    			x=j;
			}
			else if(s[j][0]==max){
				if(s[j][1]>s[x][1]){
					max=s[j][0];
					x=j;
				}
			}
		}
			printf("%d",x+1);
			if(k<m-1)
			  printf(" ");
			s[x][0]=0;	
		}
    	
		printf("\n");
	}
	return 0;
} 

Double click to view unformatted code.


Back to problem 5