about summary refs log tree commit diff
path: root/usth/MATH2.3/1/schedule.c
diff options
context:
space:
mode:
Diffstat (limited to 'usth/MATH2.3/1/schedule.c')
-rw-r--r--usth/MATH2.3/1/schedule.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/usth/MATH2.3/1/schedule.c b/usth/MATH2.3/1/schedule.c
new file mode 100644
index 0000000..6b70ca7
--- /dev/null
+++ b/usth/MATH2.3/1/schedule.c
@@ -0,0 +1,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;
+}