View Code of Problem 5

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

Double click to view unformatted code.


Back to problem 5