#include <iostream>
using namespace std;
int N, L[ 55 ] ;
//---------------------------------------------------------------------------------------------------
int LL[ 55 ] ;
int getsm( int a, int b) { // L[a] + L[a + 1] + ... + L[b]
int sm = LL[ b] ;
if ( a) sm - = LL[ a - 1 ] ;
return sm;
}
//---------------------------------------------------------------------------------------------------
int memo[ 55 ] ;
int f( int idx, int mi, int ma) {
if ( 0 <= memo[ idx] ) return memo[ idx] ;
if ( idx == N) return 1 ;
int lim = N;
if ( idx == 0 ) lim = N - 1 ;
rep( i, idx, lim) {
int sm = getsm( idx, i) ;
if ( mi <= sm and sm <= ma) {
if ( f( i + 1 , mi, ma) ) return memo[ idx] = 1 ;
}
}
return memo[ idx] = 0 ;
}
//---------------------------------------------------------------------------------------------------
void _main( ) {
cin >> N;
rep( i, 0 , N) cin >> L[ i] ;
LL[ 0 ] = L[ 0 ] ;
rep( i, 1 , N) LL[ i] = LL[ i - 1 ] + L[ i] ;
vector< int > v;
rep( i, 0 , N) rep( j, i, N) {
int sm = getsm( i, j) ;
v.push_back ( sm) ;
}
sort( all( v) ) ;
v.erase ( unique( all( v) ) , v.end ( ) ) ;
int n = v.size ( ) ;
int ans = inf;
rep( i, 0 , n) rep( j, i, n) {
int mi = v[ i] ;
int ma = v[ j] ;
rep( k, 0 , N + 1 ) memo[ k] = - 1 ;
if ( f( 0 , mi, ma) ) chmin( ans, ma - mi) ;
}
cout << ans << endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IE4sIExbNTVdOwovLy0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLQppbnQgTExbNTVdOwppbnQgZ2V0c20oaW50IGEsIGludCBiKSB7IC8vIExbYV0gKyBMW2EgKyAxXSArIC4uLiArIExbYl0KICAgIGludCBzbS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nB1c2hfYmFjayhzbSk7CiAgICB9CiAgICBzb3J0KGFsbCh2KSk7CiAgICB2LmVyYXNlKHVuaXF1ZShhbGwodikpLCB2LmVuZCgpKTsKICAgIAogICAgaW50IG4gPSB2LnNpemUoKTsKICAgIGludCBhbnMgPSBpbmY7CiAgICByZXAoaSwgMCwgbikgcmVwKGosIGksIG4pIHsKICAgICAgICBpbnQgbWkgPSB2W2ldOwogICAgICAgIGludCBtYSA9IHZbal07CiAgICAgICAgcmVwKGssIDAsIE4gKyAxKSBtZW1vW2tdID0gLTE7CiAgICAgICAgaWYgKGYoMCwgbWksIG1hKSkgY2htaW4oYW5zLCBtYSAtIG1pKTsKICAgIH0KICAgIGNvdXQgPDwgYW5zIDw8IGVuZGw7Cn0=
compilation info
prog.cpp: In function ‘int f(int, int, int)’:
prog.cpp:20:9: error: ‘i’ was not declared in this scope
rep(i, idx, lim) {
^
prog.cpp:20:20: error: ‘rep’ was not declared in this scope
rep(i, idx, lim) {
^
prog.cpp: In function ‘void _main()’:
prog.cpp:32:9: error: ‘i’ was not declared in this scope
rep(i, 0, N) cin >> L[i];
^
prog.cpp:32:16: error: ‘rep’ was not declared in this scope
rep(i, 0, N) cin >> L[i];
^
prog.cpp:36:5: error: ‘vector’ was not declared in this scope
vector<int> v;
^~~~~~
prog.cpp:36:12: error: expected primary-expression before ‘int’
vector<int> v;
^~~
prog.cpp:41:14: error: ‘v’ was not declared in this scope
sort(all(v));
^
prog.cpp:41:15: error: ‘all’ was not declared in this scope
sort(all(v));
^
prog.cpp:41:16: error: ‘sort’ was not declared in this scope
sort(all(v));
^
prog.cpp:42:26: error: ‘unique’ was not declared in this scope
v.erase(unique(all(v)), v.end());
^
prog.cpp:45:15: error: ‘inf’ was not declared in this scope
int ans = inf;
^~~
stdout