View Code of Problem 5

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

Double click to view unformatted code.


Back to problem 5