View Code of Problem 5

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

Double click to view unformatted code.


Back to problem 5