View Code of Problem 5

#include <iostream>
#include <cstdio>
using namespace std;
int main(){
    int t,a[999],b[999],n,m,max=0;
    cin>>t;
    while(t--){
        cin>>n>>m;
        for(int i=0;i<n;i++){
            cin>>a[i]>>b[i];
        }
        while(m--){
            max=0;
            for(int i=0;i<n;i++){
                if(a[i]>a[max])
                    max=i;
                else if(a[i]==a[max]&&b[i]>b[max])
                    max=i;
            }
            if(m!=0){
                cout<<max+1<<" ";
                a[max]=-1;
            }
            else{
                cout<<max+1<<endl;
                a[max]=-1;
            }

        }
            }
    return 0;
}


Double click to view unformatted code.


Back to problem 5