View Code of Problem 5

#include <iostream>
#include <algorithm>
using namespace std;

typedef struct{
public:
int a;
int b;
}fruit;

int main()
{
    int i,t,m,n,max,choose;
    cin>>t;
    for( i=0;i<t;i++){
    	cin>>n>>m;
    	fruit* f = new fruit[n];
    	for(int i=0;i<n;i++){
    		
    		cin>>f[i].a>>f[i].b;
    	}
    	for(i=0;i<m;i++){
    		max=0;
    		for(int j=0;j<n;j++){
    		if(f[j].a>max){
    		choose=j;
    		max=f[j].a;
    		}
    		else if(f[j].a==max)
    		{
    			if(f[j].b>f[choose].b)
    			choose=j;
    			}
    		}
    		f[choose].a=0;
    		f[choose].b=0;
    		if(i<m-1)
    		
    			cout<<choose+1<<" ";	
    		
    		else
    		cout<<choose+1;	
    	
    	}
    	
    }
    return 0;
    
}

Double click to view unformatted code.


Back to problem 5