#include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n, k; cin >> n >> k; vector a(n); for(int i = 0; i < n; i++){ cin >> a[i]; } vector next_diff(n); next_diff[n-1] = n; for(int i = n-2; i >= 0; i--){ if(a[i] == a[i+1]){ next_diff[i] = next_diff[i+1]; }else{ next_diff[i] = i+1; } } vector ans; int m = n; int rem = k; print_vector(next_diff); for(int i = 0; i < n; i++){ if(next_diff[i] == n){ // ココを飛ばす for(int j = i+1; j < n; j++) ans.push_back(a[j]); break; } if(a[i] < a[next_diff[i]]){ if(k == m){ for(int j = i+1; j < n; j++) ans.push_back(a[j]); break; } // k--; }else{ if(k == 1){ for(int j = i+1; j < n; j++) ans.push_back(a[j]); break; } k--; } ans.push_back(a[i]); m--; } print_vector(ans); }