about summary refs log tree commit diff
path: root/others/easy20160714/27.c
diff options
context:
space:
mode:
authorRaphael McSinyx <vn.mcsinyx@gmail.com>2017-01-02 20:37:59 +0700
committerRaphael McSinyx <vn.mcsinyx@gmail.com>2017-01-02 20:37:59 +0700
commit57d767cf4e4d5b83645bda2c4e398fdd76d059e1 (patch)
tree557cc70d5dc663b5ee3bef2be4d749ddc3cfbc4c /others/easy20160714/27.c
parent7206ecee7579a10dd347d06b397b3790e969f8f3 (diff)
downloadcp-57d767cf4e4d5b83645bda2c4e398fdd76d059e1.tar.gz
Update others/easy20160714
Diffstat (limited to 'others/easy20160714/27.c')
-rw-r--r--others/easy20160714/27.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/others/easy20160714/27.c b/others/easy20160714/27.c
new file mode 100644
index 0000000..5cf8a36
--- /dev/null
+++ b/others/easy20160714/27.c
@@ -0,0 +1,41 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+int main()
+{
+	FILE *f = fopen("INP.TXT", "r");
+	char m, n, i, j;
+	long *a, r;
+
+	fscanf(f, "%hhd %hhd", &m, &n);
+	a = malloc(m * n * sizeof(long));
+
+	for (i = 0; i < n; i++)
+		fscanf(f, "%ld", a + i);
+
+	for (i = 1; i < m; i++) {
+		fscanf(f, "%ld", a + i * n);
+		for (j = 1; j < n; j++) {
+			fscanf(f, "%ld", a + i * n + j);
+			a[i * n + j] += a[i * n + j - n - 1];
+		}
+	}
+
+	fclose(f);
+
+	r = a[n - 1];
+
+	for (i = n * 2 - 1; i < m * n; i += n)
+		if (a[i] > r)
+			r = a[i];
+
+	for (i = m * (n - 1); i < m * n; i++)
+		if (a[i] > r)
+			r = a[i];
+
+	f = fopen("OUT.TXT", "w");
+	fprintf(f, "%ld\n", r);
+	fclose(f);
+
+	return 0;
+}