#pragma GCC optimize ( "O3" ) #pragma GCC target ( "avx" ) #include using namespace std; using ll = long long; #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 FOR( VAR , INITIAL , FINAL_PLUS_ONE ) for( TYPE_OF( FINAL_PLUS_ONE ) VAR = INITIAL ; VAR < FINAL_PLUS_ONE ; VAR ++ ) #define FOREQ( VAR , INITIAL , FINAL ) for( TYPE_OF( FINAL ) VAR = INITIAL ; VAR <= FINAL ; VAR ++ ) #define QUIT return 0 #define RETURN( ANSWER ) cout << ( ANSWER ) << "\n"; QUIT #define UPDATE \ ll& dp_curr = dp[i]; \ dp_curr = dp_min + Ai; \ if( dp_min < dp_curr ){ \ if( dp_min == dp[i - K] ){ \ dp_min = dp_curr; \ FOR( j , i - K + 1 , i ){ \ const ll& dp_j = dp[j]; \ if( dp_min > dp_j ){ \ dp_min = dp_j; \ } \ } \ } \ } else if( dp_min > dp_curr ){ \ dp_min = dp_curr; \ } \ \ int main() { UNTIE; // CEXPR( int , bound_N , 200000 ); CEXPR( int , bound_N , 20 ); CIN_ASSERT( N , 2 , bound_N ); CIN_ASSERT( K , 2 , N ); ll dp[bound_N + 2]; dp[0] = 0; ll sum = 0; CEXPR( int , bound_Ai , 1000000000 ); FOR( i , 1 , K ){ CIN_ASSERT( Ai , 1 , bound_Ai ); dp[i] = Ai; sum += Ai; } ll dp_min = 0; FOREQ( i , K , N ){ CIN_ASSERT( Ai , 1 , bound_Ai ); UPDATE; sum += Ai; } RETURN( sum - dp_min ); }