View Code of Problem 5

#include<stdio.h>
void main(){
  int t;
  scanf("%d",&t);
  for(int i=0;i<t;i++){
    int n,m;
    scanf("%d%d",&n,&m);
    int a[n],b[n];
    for(int j=0;j<n;j++){
        scanf("%d%d",&a[j],&b[j]);
    }
    for(int j=0;j<m;j++){
      int s=0;
      for(int k=0;k<n;k++){
        if(a[s]<a[k]) s=k;
        if(a[s]==a[k] && b[s]<b[k]) s=k;
      }
      a[s]=0;b[s]=0;
      if(j<m-1) printf("%d ",s+1);
      else printf("%d\n",s+1);
    }
  }
}

Double click to view unformatted code.


Back to problem 5