View Code of Problem 5

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

int a[100010][2];
int main(){
	int m,n;
	int t;
	scanf("%d",&t);
	for(int i=0;i<t;i++){
		scanf("%d %d",&n,&m);
		for(int j=0;j<n;j++){
			scanf("%d %d",&a[j][0],&a[j][1]);
		}
		for(int k=0;k<m;k++){
			int maxapple=0;
			int maxpear=0;
			int pos=0;
			for(int j=0;j<n;j++){
				if(a[j][0]>maxapple){
					maxapple=a[j][0];
					maxpear=a[j][1];
					pos=j+1;
				}else if(a[j][0]==maxapple){
					if(maxpear<a[j][1]){
						maxpear=a[j][1];
						pos=j+1;
					}
				}
			}
			a[pos-1][0]=a[pos-1][1]=-1;
			if(k==0)
			printf("%d",pos);
			else
			printf(" %d",pos);
		}
		printf("\n");
	}
 
}
				

Double click to view unformatted code.


Back to problem 5