View Code of Problem 5

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

Double click to view unformatted code.


Back to problem 5