summaryrefslogtreecommitdiffstats
path: root/šola/aps1/dn/zlivanje/resitev.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'šola/aps1/dn/zlivanje/resitev.cpp')
-rw-r--r--šola/aps1/dn/zlivanje/resitev.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/šola/aps1/dn/zlivanje/resitev.cpp b/šola/aps1/dn/zlivanje/resitev.cpp
new file mode 100644
index 0000000..8926019
--- /dev/null
+++ b/šola/aps1/dn/zlivanje/resitev.cpp
@@ -0,0 +1,39 @@
+#include <sys/param.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+int compar_long (const void * a, const void * b) {
+ if (*(long *)a < *(long *)b)
+ return -1;
+ return *(long *)a > *(long *) b;
+}
+int main (void) {
+ long N, K, A;
+ scanf("%ld %ld %ld", &N, &K, &A);
+ long * d = (long *) malloc(N*sizeof *d);
+ long čet = 0;
+ long lastidx = 0;
+ long long četkončno = 1;
+ for (long i = 0; i < A && četkončno <= 2000000; i++) // pravzaprav četkončno := K**A,
+ četkončno *= K; // toda C nima int potence
+ // fprintf(stderr, "aaaaaaaa %ld\n", četkončno);
+ for (long i = 0; i < N; i++) {
+ scanf("%ld", d+i);
+ if (i && d[i-1] > d[i])
+ if (++čet >= četkončno) {
+ qsort(d+lastidx, i-lastidx, sizeof d[0], compar_long);
+ čet = 0;
+ lastidx = i;
+ }
+ }
+ qsort(d+lastidx, N-lastidx, sizeof d[0], compar_long);
+ bool devica = true;
+ for (long i = 0; i < N; i++) {
+ if (devica)
+ devica = false;
+ else
+ printf(" ");
+ printf("%ld", d[i]);
+ }
+ printf("\n");
+}