View Code of Problem 5

#include <stdio.h>
int main(){
  int t;
  scanf("%d",&t);
  int i,j,p,q,m,n,max;
  int a[9999],b[9999];
  for(i=0;i<t;i++){
    scanf("%d%d",&n,&m);
    for(j=1;j<=n;j++){
      scanf("%d%d",&a[j],&b[j]);
    }
    for(p=m;p>0;p--){
      max=1;
      for(q=2;q<=n;q++){
        if(a[q]>a[max]){
          max=q;
        }
        else if(a[q]==a[max]){
          if(b[q]>b[max])
            max=q;
          
        }
      }
      a[max]=0;
      b[max]=0;
      if(m==1)
        printf("%d",max);
      else
        printf("%d ",max);
    }
    
  
  }
  
  
  
  
  
  return 0;
}

Double click to view unformatted code.


Back to problem 5