#pragma GCC optimize ( "O3" ) #pragma GCC target ( "avx" ) #include using namespace std; #define TYPE_OF( VAR ) remove_const::type >::type #define UNTIE ios_base::sync_with_stdio( false ); cin.tie( nullptr ) #define CEXPR( LL , BOUND , VALUE ) constexpr const LL BOUND = VALUE #define CIN( LL , A ) LL A; cin >> A #define ASSERT( A , MIN , MAX ) assert( MIN <= A && A <= MAX ) #define CIN_ASSERT( A , MIN , MAX ) CIN( TYPE_OF( MAX ) , A ); ASSERT( A , MIN , MAX ) #define GETLINE( A ) string A; getline( cin , A ) #define GETLINE_SEPARATE( A , SEPARATOR ) string A; getline( cin , A , SEPARATOR ) #define FOR( VAR , INITIAL , FINAL_PLUS_ONE ) for( TYPE_OF( FINAL_PLUS_ONE ) VAR = INITIAL ; VAR < FINAL_PLUS_ONE ; VAR ++ ) #define QUIT return 0 #define RETURN( ANSWER ) cout << ( ANSWER ) << "\n"; QUIT // 入力フォーマットチェック用 // 余分な改行を許さない #define CHECK_REDUNDANT_INPUT string VARIABLE_FOR_CHECK_REDUNDANT_INPUT = ""; cin >> VARIABLE_FOR_CHECK_REDUNDANT_INPUT; assert( VARIABLE_FOR_CHECK_REDUNDANT_INPUT == "" ); assert( ! cin ); // #define CHECK_REDUNDANT_INPUT string VARIABLE_FOR_CHECK_REDUNDANT_INPUT = ""; getline( cin , VARIABLE_FOR_CHECK_REDUNDANT_INPUT ); assert( VARIABLE_FOR_CHECK_REDUNDANT_INPUT == "" ); assert( ! cin ); // |N| <= BOUNDを満たすNをSから構築 #define STOI( S , N , BOUND ) TYPE_OF( BOUND ) N = 0; { bool VARIABLE_FOR_POSITIVITY_FOR_STOI = true; assert( S != "" ); if( S.substr( 0 , 1 ) == "-" ){ VARIABLE_FOR_POSITIVITY_FOR_STOI = false; S = S.substr( 1 ); assert( S != "" ); } assert( S.substr( 0 , 1 ) != " " ); while( S == "" ? false : S.substr( 0 , 1 ) != " " ){ assert( N < BOUND / 10 ? true : N == BOUND / 10 && stoi( S.substr( 0 , 1 ) ) <= BOUND % 10 ); N = N * 10 + stoi( S.substr( 0 , 1 ) ); S = S.substr( 1 ); } if( ! VARIABLE_FOR_POSITIVITY_FOR_STOI ){ N *= -1; } if( S != "" ){ S = S.substr( 1 ); } } // 1行で入力される変数の個数が適切か確認(半角空白の個数+1を調べる) #define COUNT_VARIABLE( S , VARIABLE_NUMBER ) { int size = S.size(); int count = 0; for( int i = 0 ; i < size ; i++ ){ if( S.substr( i , 1 ) == " " ){ count++; } } assert( count + 1 == VARIABLE_NUMBER ); } int main() { UNTIE; CEXPR( int , bound_N , 200000 ); CIN_ASSERT( N , 2 , bound_N ); CIN_ASSERT( K , 1 , N ); int A[bound_N]; CIN_ASSERT( Ai_prev , 1 , N ); A[0] = Ai_prev; int ord[bound_N]; int i_min = 0; int i_max = N - 1; int i_prev = 0; FOR( i , 1 , N ){ CIN_ASSERT( Ai , 1 , N ); A[i] = Ai; if( Ai_prev < Ai ){ FOR( j , i_prev , i ){ ord[i_max--] = j; } i_prev = i; Ai_prev = Ai; } else if( Ai_prev > Ai ){ FOR( j , i_prev , i ){ ord[i_min++] = j; } i_prev = i; Ai_prev = Ai; } } CHECK_REDUNDANT_INPUT; FOR( j , i_prev , N ){ ord[i_min++] = j; } int i_K = ord[K-1]; if( i_K == 0 ){ cout << A[1]; FOR( i , 2 , N ){ cout << " " << A[i]; } } else { cout << A[0]; FOR( i , 1 , i_K ){ cout << " " << A[i]; } FOR( i , i_K + 1 , N ){ cout << " " << A[i]; } } RETURN( "" ); }