#include #include int pos[199999] = {}; int s[199999] = {}; int cmp_idx (const void *ap, const void *bp) { int a = *(int *)ap; int b = *(int *)bp; if (a == b) { return 0; } if (a > b) { return (-1)*cmp_idx(bp, ap); } if (pos[a] >= b) { return 0; } return s[pos[a]]; } int main () { int n = 0; int k = 0; int a[200000] = {}; int res = 0; int ans[200000] = {}; int b[200000] = {}; res = scanf("%d", &n); res = scanf("%d", &k); for (int i = 0; i < n; i++) { res = scanf("%d", a+i); ans[i] = i; } for (int i = 0; i < n-1; i++) { if (a[i] < a[i+1]) { s[i] = 1; } else if (a[i] > a[i+1]) { s[i] = -1; } } if (s[n-2] == 0) { pos[n-2] = n-1; } else { pos[n-2] = n-2; } for (int i = n-3; i >= 0; i--) { if (s[i] == 0) { pos[i] = pos[i+1]; } else { pos[i] = i; } } qsort(ans, n, sizeof(int), cmp_idx); for (int i = 0; i < ans[k-1]; i++) { b[i] = a[i]; } for (int i = ans[k-1]; i < n-1; i++) { b[i] = a[i+1]; } printf("%d", b[0]); for (int i = 1; i < n-1; i++) { printf(" %d", b[i]); } printf("\n"); return 0; }