summaryrefslogtreecommitdiff
path: root/1.4/skidesign.c
diff options
context:
space:
mode:
Diffstat (limited to '1.4/skidesign.c')
-rw-r--r--1.4/skidesign.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/1.4/skidesign.c b/1.4/skidesign.c
new file mode 100644
index 0000000..349d304
--- /dev/null
+++ b/1.4/skidesign.c
@@ -0,0 +1,60 @@
+/*
+ ID: mytbk921
+ LANG: C
+ TASK: skidesign
+*/
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+int compare(const void *a, const void *b)
+{
+ return *(int*)a - *(int*)b;
+}
+
+int calc_sum(int min, int N, int a[])
+{
+ int sum = 0;
+ int i;
+
+ for (i = 0; i < N && a[i] < min; i++) {
+ int diff = min - a[i];
+ sum += diff * diff;
+ }
+
+ for (i = N-1; i >= 0 && a[i] - min > 17; i--) {
+ int diff = a[i] - min - 17;
+ sum += diff * diff;
+ }
+ return sum;
+}
+
+int main()
+{
+ FILE *fin, *fout;
+ int N;
+ int m[1000];
+ int sum, ans;
+ int i;
+
+ fin = fopen("skidesign.in", "r");
+ fout = fopen("skidesign.out", "w");
+
+ fscanf(fin, "%d", &N);
+ for (i = 0; i<N; i++)
+ fscanf(fin, "%d", &m[i]);
+ fclose(fin);
+ qsort(m, N, sizeof(int), compare);
+
+ ans = calc_sum(m[0], N, m);
+ for (i = m[N-1]; i > 0; i--) {
+ sum = calc_sum(m[0]+i, N, m);
+ if (sum < ans)
+ ans = sum;
+ }
+
+ fprintf(fout, "%d\n", ans);
+ fclose(fout);
+ return 0;
+}