提交时间:2023-08-14 11:58:02
运行 ID: 98067
//20pts #include <bits/stdc++.h> using namespace std; inline int Read() { int x = 0 , f = 1; char c = getchar(); for( ; c < '0' || c > '9' ; c = getchar() ) f ^= ( c == '-' ); for( ; c >= '0' && c <= '9' ; c = getchar() ) x = ( x << 3 ) + ( x << 1 ) + ( c ^ 48 ); return f ? x : -x; } const int _ = 2e5 + 5; int n , k , v , ans; int a[_]; void DFS( int x , int num ) { if( num == k ) { int sum = 0; for( int i = 1 ; i <= n ; i++ ) { sum += a[ i ] - v; if( sum < 0 ) sum = 0; ans = max( ans , sum ); } return; } if( x > n ) return; DFS( x + 1 , num ); a[ x ] += 2 * v; DFS( x + 1 , num + 1 ); a[ x ] -= 2 * v; } void Subtask1() { DFS( 1 , 0 ); cout << ans << '\n'; } int main() { n = Read() , k = Read() , v = Read(); for( int i = 1 ; i <= n ; i++ ) { a[ i ] = Read(); } if( n <= 8 ) Subtask1(); return 0; }