View Code of Problem 5

#include<iostream>
using namespace std;
class Basket{
public:
    int m_Apple;int m_Pear;
    int id;
};
int main(){
    int t;
    cin>>t;
    while(t>0){
        int n,m;
        cin>>n>>m;
        Basket basket[n];
        for(int i=0;i<n;i++){
            int apple,pear;
            cin>>apple>>pear;
            basket[i].m_Apple=apple;
            basket[i].m_Pear=pear;
            basket[i].id=i;
        }
        for(int i=0;i<m;i++){
            Basket temp=basket[0];
            int p=0;
            for(int j=0;j<n;j++){
                if(basket[j].m_Apple>temp.m_Apple||(basket[j].m_Apple==temp.m_Apple&&basket[j].m_Pear>temp.m_Pear)){
                        p=j;
                        temp=basket[p];
                }
            }
            basket[p].m_Pear=-1;
            basket[p].m_Apple=-1;
            cout<<p+1<<" ";
        }
        cout<<endl;
        t--;
    }

    return 0;
}

Double click to view unformatted code.


Back to problem 5