View Code of Problem 5

#include "stdlib.h"
#include "iostream"
#include "string.h"
#include "math.h"
using namespace std;
int main()
{
	int t;
	scanf("%d", &t);
	while (t--)
	{
		int n = 0; int m = 0;
		int a[999], b[999] ;
		scanf("%d %d", &n, &m);
		for (int i = 1; i <= n; i++)
		{
			scanf("%d %d", &a[i], &b[i]);
		}
		for (int i = 1; i <= m; i++)
		{
			int k = 1;
			for (int j = 1; j <= n; j++)
			{
				if (a[j] > a[k])k = j;
				else if (a[k] == a[j] && b[j] > b[k])k = j;
			}
			printf("%d", k);
			a[k] = -1;
			if (i < m)printf(" ");
		}
		printf("\n");
	}
}

Double click to view unformatted code.


Back to problem 5