about summary refs log tree commit diff
path: root/usth/MATH2.3/1/schedule.c
diff options
context:
space:
mode:
authorNguyễn Gia Phong <vn.mcsinyx@gmail.com>2020-01-14 18:29:11 +0700
committerNguyễn Gia Phong <vn.mcsinyx@gmail.com>2020-01-14 18:29:11 +0700
commita3dd2581ed4847670f81157091016c14ca18803d (patch)
tree3362ab15de119f1e75799f58715b7683e6bfd6ca /usth/MATH2.3/1/schedule.c
parent65b8ebda4c47fa27ac28899fb2b29097f445b6df (diff)
downloadcp-a3dd2581ed4847670f81157091016c14ca18803d.tar.gz
[usth/MATH2.3] Mathemate Discretely
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;
+}