View Code of Problem 5

#include<stdio.h>
#include <string.h>
#include <math.h>
int main(){
	int t;
	int i;
	int n,m;
	int a[1000];
	int p[1000];
	scanf("%d",&t);
	while(t>0){
		scanf("%d %d",&n,&m);
		for(i=0;i<n;i++){
			scanf("%d %d",&a[i],&p[i]);
		}
		while(m>0){
			int max=0;
			for(i=0;i<n;i++){
				if(a[i]>a[max]){
					max=i;
				}
				else if(a[i]==a[max]){
					if(p[i]>p[max]){
						max=i;
					}
				}
			}
			if(m>1)  
			printf("%d ",max+1);
		    else 
			printf("%d\n",max+1);
			a[max]=0;
			p[max]=0;
			m--;
		}
		t--;
	}
	
	return 0;
}

Double click to view unformatted code.


Back to problem 5