View Code of Problem 5

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

  }

}

Double click to view unformatted code.


Back to problem 5