View Code of Problem 5

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


Double click to view unformatted code.


Back to problem 5