View Code of Problem 5

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n >>m;
        int a[n][2];
        for(int i=0;i<n;++i)
        {
            cin>>a[i][0] >>a[i][1];
        }

        for(int i=0;i<m;++i)
        {
            int k=0;
            for(int j=0;j<n;++j)
            {
                if(a[k][0]<a[j][0])
                    k=j;
                else if(a[k][0]==a[j][0]&&a[k][1]<a[j][1])
                k=j;
            }
            printf("%d",k+1);
            if(i<m-1)
                printf(" ");
            a[k][0]=0;
        }
        printf("\n");
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 5