// 提出時に定数倍高速化,assertはオフ #ifndef DEBUG #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") #ifndef NDEBUG #define NDEBUG #endif #endif #include using namespace std; using ll = long long; #define all(x) (x).begin(), (x).end() template using vec = vector; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N, K; cin >> N >> K; vecA(N); for(int &a : A) cin >> a; stack cur; vec ans(N, -1); int frontIndex = 0, backIndex = N - 1; for(int i = 0; i < N; i++){ if(cur.empty()){ cur.push(i); continue; } if(A[cur.top()] > A[i]){ while(!cur.empty()){ ans[frontIndex++] = cur.top(); cur.pop(); } } else if(A[cur.top()] < A[i]){ while(!cur.empty()){ ans[backIndex--] = cur.top(); cur.pop(); } } cur.push(i); } while(!cur.empty()){ ans[frontIndex++] = cur.top(); cur.pop(); } /* for(int i = 0; i < N; i++){ cout << ans[i] << "\n"; } //*/ //* int ansIndex = ans[K - 1]; for(int i = 0; i < N; i++){ if(i != ansIndex) cout << A[i] << " "; } cout << "\n"; //*/ }