/** * @file 2559.cpp * @brief yukicoder 眩しい数直線 * @author Keitaro Naruse * @date 2023-12-02 * @copyright MIT License * @details https://yukicoder.me/problems/no/2559 * */ // # Solution #include #include #include template < class T > std::ostream& operator<<( std::ostream& os, const std::vector< T >& v ) { for( auto it = v.begin( ); it != v.end( ); it++ ) { os << *it << ( it == --v.end( ) ? "" : " " ); } return os; } int main( ) { // Read N = [ 1, 10^3 ], X = [ 1, 10^3 ] int N, X; std::cin >> N >> X; // Read Ai = [ 1, X ], Bi = [ 1, 10^3 ] std::vector< int > A( N ), B( N ); for( int i = 0; i < N; i++ ) { std::cin >> A.at( i ) >> B.at( i ); } // Main::Preprocess for( int i = 0; i < N; i++ ) { A.at( i )--; } // Main::Find a solution std::vector< int > L( X, 0 ); for( int i = 0; i < N; i++ ) { for( int j = 0; j < B.at( i ); j++ ) { if( j == 0 ) { L.at( A.at( i ) ) = std::max( L.at( A.at( i ) ), B.at( i ) ); } else { if( A.at( i ) - j >= 0 ) { L.at( A.at( i ) - j ) = std::max( L.at( A.at( i ) - j ), B.at( i ) - j ); } if( A.at( i ) + j < X ) { L.at( A.at( i ) + j ) = std::max( L.at( A.at( i ) + j ), B.at( i ) - j ); } } } } // Main::Output a solution std::cout << L << std::endl; // Finalize return 0; }