View Code of Problem 5

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

Double click to view unformatted code.


Back to problem 5