View Code of Problem 5

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

Double click to view unformatted code.


Back to problem 5