View Code of Problem 5

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

class Backet{

public:
	int apple, pear, pos;
	Backet(int apple, int pear, int pos){
		this->apple=apple;
		this->pear=pear;
		this->pos=pos;
	}
};

bool cmp(Backet b1, Backet b2){
	if(b1.apple>b2.apple)
		return true;
	else if(b1.apple==b2.apple&&b1.pear>b2.pear)
		return true;
	else if(b1.apple==b2.apple&&b1.pear==b2.pear&&b1.pos<b2.pos)
		return true;
	else
		return false;
}

int main(){
	
	int t;
	int n, m;
	int a, b;
	vector<Backet> v;
	cin>>t;
	for(int i=0; i<t; i++){
		cin>>n>>m;
		for(int j=1; j<=n; j++){
			cin>>a>>b;
			Backet backet(a, b, j);
			v.push_back(backet);
		}
		sort(v.begin(), v.end(), cmp);
		
		for(int k=0; k<m; k++){
			if(k==0)
				cout<<v[k].pos;
			else
				cout<<" "<<v[k].pos;
		}
		cout<<endl;
		v.clear();
	}
	
	return 0;
}

Double click to view unformatted code.


Back to problem 5