View Code of Problem 5

#include <bits/stdc++.h>
using namespace std;
typedef struct fru
{
    int a,b,id;
}fru;
bool cmp(fru q, fru w)
{
    if(q.a!=w.a)
        return q.a>w.a;
    else if(q.a==w.a&&q.b!=w.b)
        return q.b>w.b;
    else if(q.a==w.a&&q.b==w.b)
        return q.id<w.id;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n >>m;
        fru wa[n];
        for(int i=0;i<n;++i)
        {
            cin>>wa[i].a >>wa[i].b;
            wa[i].id=i;
        }
        sort(wa,wa+n,cmp);
        for(int i=0;i<m;++i)
        {
            cout<<wa[i].id+1;
            if(i<m-1)
                cout<<" ";
        }
        cout<<endl;
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 5