149. [CPE] Rockabye Tobby

 avatar
user_6817964
c_cpp
2 years ago
945 B
3
Indexable
Never
struct data {
	char med[15];
	int time;
	int square;
};

void F(struct data* array, int size, int* k) {
	if ((*k) != 0) {
		int min = array[0].time, index = 0;
		for (int i = 1; i < size; i++) {
			if (array[i].time < min) {
				min = array[i].time;
				index = i;
			}
			else if (array[i].time == min) {
				if (i < index) {
					min = array[i].time;
					index = i;
				}
			}
		}

	    printf("%d %s\n", array[index].time, array[index].med);

		array[index].time += array[index].square;
		(*k) = (*k) - 1;
		F(array, size, k);
	}
}

int main() {
	int T, n, k;
	struct data* Array;
	scanf("%d", &T);

	for (int i = 0; i < T; i++) {
		scanf("%d %d", &n, &k);
		Array = (struct data*)malloc(sizeof(struct data) * n);

		for (int j = 0; j < n; j++) {
			scanf("%s", &Array[j].med);
			scanf("%d", &Array[j].time);
			Array[j].square = Array[j].time;
		}

		F(Array, n, &k);

		free(Array);
	}

}