View Code of Problem 5

#include <stdio.h>
#include <string.h>
#include <math.h>
struct basket {
	int apple;
	int pear;
};
int main()
{
	int t, n, m, i, j, k;
	struct basket ba[100000];
	scanf("%d", &t);
	while (t--)
	{
		scanf("%d%d", &n, &m);
		for (i = 0; i < n; i++)
			scanf("%d%d", &ba[i].apple, &ba[i].pear);
		while (m--)
		{
			int max=0;
			for (j = 0; j < n; j++)
			{
				if (ba[j].apple > ba[max].apple)
					max = j;
				else if (ba[j].apple == ba[max].apple && ba[j].pear > ba[max].pear)
					max = j;
				else if (ba[j].apple == ba[max].apple && ba[j].pear == ba[max].pear)
				{
					if (j > max)
						continue;
					else
						max = j;
				}
				else
					continue;
			}
			printf("%d", max + 1);
			if (m == 0)
				printf("\n");
			else
				printf(" ");
			ba[max].apple = 0;
			ba[max].pear = 0;
		}
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 5