View Code of Problem 5

#include "stdlib.h"
#include "iostream"
#include "string.h"
#include "math.h"
int main()
{
	int t;
	scanf("%d", &t);
	while (t--)
	{
		int n, m;  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(" ");
		}
	}
	system("pause");
}

Double click to view unformatted code.


Back to problem 5