View Code of Problem 5

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

struct basket
{
    int index;
    int a,p;
};
basket fruit[10000];

bool cmp(basket x,basket y)
{
    if(x.a==y.a&&y.p==x.p)
        return x.index<y.index;
    else if(x.a==y.a)
        return x.p>y.p;
    else
        return x.a>y.a;
}

int main()
{
    int t;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        int n,m;
        cin>>n>>m;
        int t=0;
        for(int j=0;j<n;j++)
        {
            scanf("%d%d",&fruit[j].a,&fruit[j].p);
            fruit[j].index=++t;
        }
        sort(fruit,fruit+n,cmp);
        for(int k=0;k<m;k++)
        {
            cout<<fruit[k].index<<" ";
        }
        cout<<endl;
    }
    return 0;
}

/*
Main.c:1:19: fatal error: iostream: No such file or directory
 #include<iostream>
                   ^
compilation terminated.
*/

Double click to view unformatted code.


Back to problem 5