View Code of Problem 5

#include<stdio.h>
#include<string.h>
#define N 100000
int main() {
    int x;
    scanf("%d",&x);
    while (x--)
    {
        int n, m;
        scanf("%d %d",&n,&m);
        int arr[N][2];
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < 2; j++)
            {
                scanf("%d", &arr[i][j]);
            }
        }

        while (m--)
        {
            int max = 0;
            for (int i = 0; i < n; i++)
            {
                if (arr[max][0]<arr[i][0])
                {
                    max = i;
                }
                else if (arr[max][0] == arr[i][0])
                {
                    if (arr[max][1] < arr[i][1])
                    {
                        max = i;
                    }

                }
            }
            if (m > 0)
                printf("%d ", max + 1);
            else
                printf("%d\n", max + 1);
            arr[max][0] = arr[max][1] = 0;
        }
    }
    return 0;

}

Double click to view unformatted code.


Back to problem 5