about summary refs log tree commit diff
path: root/12/QG-2007/maxiseq.c
diff options
context:
space:
mode:
authorRaphael McSinyx <vn.mcsinyx@gmail.com>2017-08-11 13:43:15 +0700
committerRaphael McSinyx <vn.mcsinyx@gmail.com>2017-08-11 13:43:15 +0700
commitebb579dd31a19a4d08a8e9aae97c5fc354bc3e8b (patch)
treed1c5f7c374e209a16fa0a30046afdce57cef249a /12/QG-2007/maxiseq.c
parent14f5f67c1b3ade42498d8a0988c671fe23a3f46e (diff)
downloadcp-ebb579dd31a19a4d08a8e9aae97c5fc354bc3e8b.tar.gz
Add 12/QG-2007/maxiseq.c
Diffstat (limited to '12/QG-2007/maxiseq.c')
-rw-r--r--12/QG-2007/maxiseq.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/12/QG-2007/maxiseq.c b/12/QG-2007/maxiseq.c
new file mode 100644
index 0000000..94c15c8
--- /dev/null
+++ b/12/QG-2007/maxiseq.c
@@ -0,0 +1,36 @@
+#include <math.h>
+#include <stdio.h>
+
+char is_in_u(long x)
+{
+	long y = (long) sqrt(x *= 2);
+	return y * (y + 1) == x;
+}
+
+int main()
+{
+	FILE *f = fopen("MAXISEQ.INP", "r");
+	short n, i, max = 0, start = -1;
+	long a, b;
+
+	fscanf(f, "%hd\n", &n);
+	for (i = 0; i < n; i++) {
+		b = a;
+		fscanf(f, "%ld\n", &a);
+		if (!is_in_u(a) || start >= 0 && b > a) {
+			start = -1;
+			continue;
+		}
+		if (start < 0)
+			start = i;
+		if (i - start >= max)
+			max = i - start + 1;
+	}
+	fclose(f);
+
+	f = fopen("MAXISEQ.OUT", "w");
+	fprintf(f, "%hd\n", max);
+	fclose(f);
+
+	return 0;
+}