about summary refs log tree commit diff
path: root/usth/MATH2.3/1/schedule.c
blob: 6b70ca7d37bdc2cc4660b43b222e31edfa11de23 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <stdio.h>
#include <stdlib.h>

struct talk {
	int start, end;
};

int cmp(const void *x, const void *y)
{
	return ((struct talk *) x)->end - ((struct talk *) y)->end;
}

int main()
{
	size_t n;
	scanf("%zu", &n);
	struct talk *a = malloc(n * sizeof(struct talk));
	for (size_t i = 0; i < n; ++i)
		scanf("%d %d", &a[i].start, &a[i].end);

	qsort(a, n, sizeof(struct talk), cmp);
	int start = a->start;
	for (size_t i = 0; i < n; ++i)
		if (a[i].start >= start) {
			printf("%d %d\n", a[i].start, a[i].end);
			start = a[i].end;
		}

	return 0;
}