View Code of Problem 5

#include<cstdio>
#include<vector>
using namespace std;
const int maxn=100010;
int main(){
	int t;
	//freopen("5.txt","r",stdin);
	scanf("%d",&t);
	for(int i=0;i<t;i++){
		int n,m;
		scanf("%d %d",&n,&m);
		vector<int> a(n+1),b(n+1);
		for(int j=1;j<=n;j++){
			scanf("%d %d",&a[j],&b[j]);	
		}
		for(int k=m;k>0;k--){
			int ans=1;
			int maxn1=a[1],maxn2=b[1];
			for(int j=2;j<=n;j++){
				if(a[j]>maxn1||(a[j]==maxn1&&b[j]>maxn2)){
					ans=j;
				}
			}
			a[ans]=0;
			a[ans]=0;
			if(k!=1)	printf("%d ",ans);
			else	printf("%d",ans);
		}
		if(i!=t-1)	printf("\n");		
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 5