summaryrefslogtreecommitdiffstats
path: root/inf/rtk/2021-izbirno/2
diff options
context:
space:
mode:
Diffstat (limited to 'inf/rtk/2021-izbirno/2')
-rwxr-xr-xinf/rtk/2021-izbirno/2/a.outbin0 -> 20696 bytes
-rw-r--r--inf/rtk/2021-izbirno/2/in.txt2
-rw-r--r--inf/rtk/2021-izbirno/2/prog.c64
3 files changed, 66 insertions, 0 deletions
diff --git a/inf/rtk/2021-izbirno/2/a.out b/inf/rtk/2021-izbirno/2/a.out
new file mode 100755
index 0000000..d23cc33
--- /dev/null
+++ b/inf/rtk/2021-izbirno/2/a.out
Binary files differ
diff --git a/inf/rtk/2021-izbirno/2/in.txt b/inf/rtk/2021-izbirno/2/in.txt
new file mode 100644
index 0000000..666efb4
--- /dev/null
+++ b/inf/rtk/2021-izbirno/2/in.txt
@@ -0,0 +1,2 @@
+10 1
+6 0 91 14 73 91 67 63 9 69
diff --git a/inf/rtk/2021-izbirno/2/prog.c b/inf/rtk/2021-izbirno/2/prog.c
new file mode 100644
index 0000000..eda85e9
--- /dev/null
+++ b/inf/rtk/2021-izbirno/2/prog.c
@@ -0,0 +1,64 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <limits.h>
+int primerjaj_cela (const void * a, const void * b) {
+ const int * c = (const int *) a;
+ const int * d = (const int *) b;
+ return *d - *c; /* najv proti najm */
+}
+int main (int argc, char ** argv) {
+ char * buf = malloc(500);
+ fgets(buf, 500, stdin);
+ char * cp;
+ int N = strtoll(buf, &cp, 10);
+ cp++;
+ int M = strtoll(cp, NULL, 10);
+ int * x = calloc(N+1, sizeof(int));
+ int * g = malloc((M+1)*sizeof(int));
+ int * gl = malloc((M+1)*sizeof(int));
+ for (int o = 0; o < M; o++)
+ g[o] = INT_MAX;
+ realloc(buf, (N+1)*6*9);
+ fgets(buf, (N+1)*6*9, stdin);
+ cp = buf;
+ int i = 0;
+ int mx = 0;
+ do {
+ int xi = strtoll(cp, &cp, 10);
+ // if (xi != 0)
+ x[++i] = xi;
+ if (xi > mx)
+ mx = xi;
+ cp++;
+ } while (cp[-1] != 0 && cp[-1] != '\n' && cp[-1] != '\r');
+ free(buf);
+ if (N != i) {
+ fprintf(stderr, "error %d ni %d\n", N, i);
+ for (int o = 1; o <= i; o++)
+ fprintf(stderr, " %d\n", x[o]);
+ }
+ fprintf(stderr, "max = %d\n", mx);
+ for (i = 0; i <= mx; i++) {
+ int s = 0;
+ for (int j = 1; j <= N; j++)
+ s += abs(i-x[j]);
+ int mo = 0;
+ int me = 0;
+ for (int o = 0; o < M; o++) {
+ if (g[o] > mo) {
+ mo = g[o];
+ me = o;
+ }
+ }
+ if (mo > s)
+ g[me] = s;
+ }
+ int s = 0;
+ for (int o = 0; o < M; o++) {
+ fprintf(stderr, "GOSTILNA %d ima seštevek %d\n", o, g[o]);
+ s += g[o];
+ }
+ fprintf(stdout, "%d\n", s);
+ return 0;
+}