Problem:
水ようかん (Mizuyokan)
問題文
水ようかんとは，おもに小豆からなる餡を型に流し込んで寒天で固めることにより作られる和菓子である．いま，JOI 君の手元には，横長の直方体の形をした水ようかんがひとつある．JOI 君は，今日のおやつとしてこの水ようかんを食べる予定である．
この水ようかんには，縦方向の切れ目が全部で
N-1
箇所に入っている．水ようかんの長さは
L_1 + L_2 + ... + L_N
であり，
i
番目
(1 ≦ i ≦ N-1)
の切れ目は，左から
L_1 +  L_2 +  ... +  L_i
の位置にある．
この水ようかんは丸ごと食べるには大きすぎるので，JOI 君は，水ようかんに入っている切れ目から
1
箇所以上を選び，選んだ切れ目に沿って水ようかんを切って，複数のピースに切り分けることにした．ただし，ピースの大きさが不揃いでは見栄えが悪いので，長さ最大のピースと最小のピースの長さの差ができるだけ小さくなるように切ることにした．
長さ最大のピースと最小のピースの長さの差の最小値を求めよ．
制約
2 \leq N \leq 50
1 \leq L_i \leq 1000 (1 \leq i \leq N)
入力・出力
入力
入力は以下の形式で標準入力から与えられる．
N
L_1
L_2
:
L_N
出力
長さ最大のピースと最小のピースの長さの差の最小値を
1
行で出力せよ．
入出力例
入力例 1
11
2
3
8
4
7
6
6
5
1
7
5
出力例 1
2
この例では，
4
番目および
7
番目の切れ目に沿って切り分けることで，長さ
17, 19, 18
の
3
つのピースに切り分けることができる．
このとき，いちばん長いピースは長さ
19
で，いちばん短いピースは長さ
17
であるので，長さの差は
2
となる．
これが最小値なので，
2
を出力する．
入力例 2
2
1
10
出力例 2
9
どんなに大きさが不揃いであっても，必ず
1
箇所以上を切る必要がある．
入力例 3
5
5
5
5
5
5
出力例 3
0
この例では水ようかんをちょうど同じ大きさの
5
つのピースに分割できる．
情報オリンピック日本委員会作 『第 17 回日本情報オリンピック JOI 2017/2018 予選競技課題』

Submitted solutions:

code_snippet: #include <iostream>
#include <cstdint>
#include <vector>

using namespace std;

int main()
{
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	
	uint16_t N, i;
	cin >> N;
	vector<uint16_t> L(N);
	for (i = 0; i != N; ++i) cin >> L[i];

	uint16_t length = 0;
	for (i = 0; i != N; ++i) length += L[i];

	uint16_t l, r, S, S_min, S_max, ans = UINT16_MAX;
	for (r = 1; r != length; ++r)
		for (l = 1; l <= r; ++l)
		{
			S = 0, S_min = UINT16_MAX, S_max = 0;
			for (i = 0; i != N; ++i)
			{
				S += L[i];
				if (S > r) break;
				else if (S >= l)
				{
					if (S < S_min) S_min = S;
					if (S > S_max) S_max = S;
					S = 0;
				}
			}

			if (i == N)
			{
				if (S != 0)
				{
					if (S < S_min) S_min = S;
					if (S > S_max) S_max = S;
				}

				if (S_max - S_min < ans) ans = S_max - S_min;
			}
		}

	cout << ans << '\n';
	return 0;
}
accuracy: 0.3058823529411765
time_ms: 1490
memory_kb: 3448
final_rank: 18

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,l,r) for(ll i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(A) A.begin(),A.end()
#define LB(A,x) (lower_bound(ALL(A),x)-A.begin())
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return 1;}return 0;}
int main(){
    int N;cin>>N;
    vector<ll>L(N+1);
    REP(i,N){
        cin>>L[i+1];
        L[i+1]+=L[i];
    }
    vector<vector<ll>>DP(N+1,vector<ll>(L[N],1e18));
    DP[0][L[N]-1]=0;
    FOR(i,1,N+1)REP(j,i)if(i-j<N){
        REP(k,L[N]){
            ll d=L[i]-L[j];
            chmin(DP[i][min(k,d)],max(d,DP[j][k]));
        }
    }
    ll ans=1e18;
    REP(i,L[N])chmin(ans,DP[N][i]-i);
    cout<<ans<<endl;
    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 22928
final_rank: 13

code_snippet: #include<bits/stdc++.h>
using namespace std;

int main(){
    cin.tie(nullptr)->ios::sync_with_stdio(false);
    int64_t res = INT64_MAX;
    int64_t N; cin >> N;
    vector<int64_t> L(N); for(auto &in : L) cin >> in;
    vector<int64_t> pref = {0}; for(auto l : L) pref.push_back(pref.back() + l);
    for(int64_t mi = 1; mi <= pref[N-1]; mi++){
        int64_t pass = 60000, fail = mi-1;
        while(pass - fail > 1){
            int64_t mx = fail + (pass - fail) / 2;
            vector<bool> ok(N+1, false);
            ok[0] = true;
            for(int64_t pos = 1; pos <= N; pos++){
                for(int64_t bk = pos-1; bk >= 0; bk--){
                    int64_t siz = pref[pos]-pref[bk];
                    if(siz < mi or mx < siz) continue;
                    if(pos == N and bk == 0) continue;
                    if(ok[bk]){
                        ok[pos] = true;
                        break;
                    }
                }
            }
            (ok[N] ? pass : fail) = mx;
        }
        res = min(res, pass - mi);
    }
    cout << res << '\n';
}
accuracy: 1
time_ms: 500
memory_kb: 3460
final_rank: 10

code_snippet: #include<bits/stdc++.h>
using namespace std;

int main(){
    cin.tie(nullptr)->ios::sync_with_stdio(false);
    int64_t res = INT64_MAX;
    int64_t N; cin >> N;
    vector<int64_t> L(N); for(auto &in : L) cin >> in;
    vector<int64_t> pref = {0}; for(auto l : L) pref.push_back(pref.back() + l);
    for(int64_t mi = 1; mi <= pref[N-1]; mi++){
        int64_t pass = pref.back(), fail = mi-1;
        while(pass - fail > 1){
            int64_t mx = fail + (pass - fail) / 2;
            vector<bool> ok(N+1, false);
            ok[0] = true;
            for(int64_t pos = 1; pos <= N; pos++){
                for(int64_t bk = pos-1; bk >= 0; bk--){
                    int64_t siz = pref[pos]-pref[bk];
                    if(siz < mi or mx < siz) continue;
                    if(ok[bk]){
                        ok[pos] = true;
                        break;
                    }
                }
            }
            (ok[N] ? pass : fail) = mx;
        }
        res = min(res, pass - mi);
    }
    cout << res << '\n';
}
accuracy: 0.24705882352941178
time_ms: 10
memory_kb: 3504
final_rank: 20

code_snippet: #include<bits/stdc++.h>
using namespace std;

int main(){
    cin.tie(nullptr)->ios::sync_with_stdio(false);
    int64_t res = INT64_MAX;
    int64_t N; cin >> N;
    vector<int64_t> L(N); for(auto &in : L) cin >> in;
    vector<int64_t> pref = {0}; for(auto l : L) pref.push_back(pref.back() + l);
    for(int64_t mi = 0; mi <= pref[N-1]; mi++){
        int64_t pass = pref.back(), fail = mi-1;
        while(pass - fail > 1){
            int64_t mx = fail + (pass - fail) / 2;
            vector<bool> ok(N+1, false);
            ok[0] = true;
            for(int64_t pos = 1; pos <= N; pos++){
                for(int64_t bk = pos-1; bk >= 0; bk--){
                    int64_t siz = pref[pos]-pref[bk];
                    if(siz < mi or mx < siz) continue;
                    if(ok[bk]){
                        ok[pos] = true;
                        break;
                    }
                }
            }
            (ok[N] ? pass : fail) = mx;
        }
        res = min(res, pass - mi);
    }
    cout << res << '\n';
}
accuracy: 0.24705882352941178
time_ms: 10
memory_kb: 3460
final_rank: 19

code_snippet: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int n, l, rui[55], ma[55], ans;
    cin >> n;
    rui[0] = 0;
    for(int i=1;i<=n;i++){
        cin >> l;
        rui[i] = l+rui[i-1];
    }
    ans = rui[n]*2;
    for(int mi=1;mi<rui[n];mi++){
        for(int j=1;j<=n;j++){
            ma[j] = rui[n]*2;
            if(j < n && rui[j] >= mi) ma[j] = rui[j];
            for(int k=1;k<j;k++){
                if(ma[k] < mi || rui[j]-rui[k] < mi) continue;
                ma[j] = min(ma[j], max(ma[k], rui[j]-rui[k]));
            }
        }
        ans = min(ans, ma[n]-mi);
    }
    cout << ans << endl;
    return(0);
}
accuracy: 1
time_ms: 60
memory_kb: 3092
final_rank: 7

code_snippet: #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
    int n, l, rui[55], ma[55], ans;
    vector<int> mi;
    cin >> n;
    rui[0] = 0;
    for(int i=1;i<=n;i++){
        cin >> l;
        rui[i] = l+rui[i-1];
    }
    ans = rui[n]+rui[n];
    for(int mi=1;mi<rui[n];mi++){
        for(int j=1;j<=n;j++){
            ma[j] = rui[n]+rui[n];
            if(j < n && rui[j] >= mi) ma[j] = rui[j];
            for(int k=1;k<j;k++){
                if(rui[k] < mi || ma[k] < mi || rui[j]-rui[k] < mi) continue;
                ma[j] = min(ma[j], max(ma[k], rui[j]-rui[k]));
            }
        }
        ans = min(ans, ma[n]-mi);
    }
    cout << ans << endl;
    return(0);
}
accuracy: 1
time_ms: 50
memory_kb: 3092
final_rank: 4

code_snippet: #include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define rep3(i, x, y) for(ll i = x; i < y; i++)
#define rep4(i, x) for(ll i = x; i >= 0; i--)
#define all(a) (a).begin(),(a).end()
#define puts(x) cout << (x) << "\n"
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const int intINF = 1000000000;
const ll mod = 1000000007;
const ll MOD = 998244353;
const ld pi = 3.141592653589793238;
//const ld EPS = 1e-9;

bool isprime(int p) {
	if (p == 1) return false;
	for (int i = 2; i < p; i++) {
		if (p % i == 0) return false;
	}
	return true;
}
ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	return gcd(b, a % b);
}
//ax + by = cが整数解をもつための必要十分条件は c が gcd(a,b) で割り切れること。
// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
//main関数内に extGCD(a, b, x, y); でx, yに解が格納
ll extGCD(ll a, ll b, ll& x, ll& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	ll d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll keta(ll n) {
	ll res = 0;
	while (n >= 1) {
		res++; //res += n % 10;
		n /= 10;
	}
	return res;
}
ll modpow(ll x, ll y, ll m) {
	ll res = 1;
	while (y) {
		if (y % 2) { res *= x; res %= m; }
		x = x * x % m; y /= 2;
	}
	return res;
}
ll kaijyo[1000005];
void nCkinit(ll n, ll m) {
	ll cnt = 1; kaijyo[0] = 1;
	for (int h = 1; h <= n; h++) { cnt *= h; cnt %= m; kaijyo[h] = cnt; }
}
ll nCk(ll n, ll k, ll m) {
	/*ll a = 1, b = 1;
	for (int h = 1; h <= n; h++) { a *= h; a %= m; }
	for (int h = 1; h <= k; h++) { b *= h; b %= m; }
	for (int h = 1; h <= n - k; h++) { b *= h; b %= m; }*/
	ll a = kaijyo[n], b = kaijyo[k] * kaijyo[n - k] % m;
	return a * modpow(b, m - 2, m) % m;
}
//printf("%.10f\n", n);
typedef pair <ll, ll> P;
typedef pair <string, string> pp;
ll dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
struct edge { ll to, cost; };
struct Point {
	ll x, y;
};
bool operator<(const Point& a1, const Point& a2) {
	if (a1.x < a2.x) return true;
	if (a1.x > a2.x) return false;
	if (a1.y < a2.y) return true;
	return false;
}


vector<ll> spf;
void smallest_prime_factors(ll n) {
	spf.resize(n + 1); spf[1] = 1;
	for (int i = 2; i <= n; i++) {
		if (!spf[i]) {
			for (int j = i; j < n; j += i) { spf[j] = i; }
		}
	}
}
std::map<int, int> high_speed_prime_factor(int n) {
	std::map<int, int> res;
	while (n != 1) {
		res[spf[n]]++;
		n /= spf[n];
	}
	return res;
}

struct status {
	ll a; ll b; ll s;

	bool operator<(const status& rhs) const { return s < rhs.s; };
	bool operator>(const status& rhs) const { return s > rhs.s; };
};

int main() {
	srand((unsigned)time(NULL));
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	//cout << fixed << setprecision(15);

	ll n, ma = 0, sum = 0; cin >> n;
	vector<ll>l(n + 1);
	rep2(i, n) { cin >> l[i]; sum += l[i]; ma = max(ma, l[i]); }
	ll ans = INF;
	for (int i = ma; i < sum; i++) {//上限
		vector<ll>dp(n + 1);//i番目を切る時の最小値の最大値
		dp[0] = INF;
		rep2(j, n) {
			ll lsum = 0;
			for (int k = j; k > 0; k--) {
				lsum += l[k];
				if (lsum > i) { break; }
				else { dp[j] = max(dp[j], min(dp[k - 1], lsum)); }
			}
		}
		ans = min(ans, i - dp[n]);
	}
	cout << ans << endl;
	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3468
final_rank: 5

code_snippet: #include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<ctime>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<bitset>
#include<functional>
#include <fstream>
//#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define rep3(i, x, y) for(ll i = x; i < y; i++)
#define rep4(i, x) for(ll i = x; i >= 0; i--)
#define all(a) (a).begin(),(a).end()
#define puts(x) cout << (x) << "\n"
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const int intINF = 1000000000;
const ll mod = 1000000007;
const ll MOD = 998244353;
const ld pi = 3.141592653589793238;
//const ld EPS = 1e-9;

bool isprime(int p) {
	if (p == 1) return false;
	for (int i = 2; i < p; i++) {
		if (p % i == 0) return false;
	}
	return true;
}
ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	return gcd(b, a % b);
}
//ax + by = cが整数解をもつための必要十分条件は c が gcd(a,b) で割り切れること。
// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
//main関数内に extGCD(a, b, x, y); でx, yに解が格納
ll extGCD(ll a, ll b, ll& x, ll& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	ll d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll keta(ll n) {
	ll res = 0;
	while (n >= 1) {
		res++; //res += n % 10;
		n /= 10;
	}
	return res;
}
ll modpow(ll x, ll y, ll m) {
	ll res = 1;
	while (y) {
		if (y % 2) { res *= x; res %= m; }
		x = x * x % m; y /= 2;
	}
	return res;
}
ll kaijyo[1000005];
void nCkinit(ll n, ll m) {
	ll cnt = 1; kaijyo[0] = 1;
	for (int h = 1; h <= n; h++) { cnt *= h; cnt %= m; kaijyo[h] = cnt; }
}
ll nCk(ll n, ll k, ll m) {
	/*ll a = 1, b = 1;
	for (int h = 1; h <= n; h++) { a *= h; a %= m; }
	for (int h = 1; h <= k; h++) { b *= h; b %= m; }
	for (int h = 1; h <= n - k; h++) { b *= h; b %= m; }*/
	ll a = kaijyo[n], b = kaijyo[k] * kaijyo[n - k] % m;
	return a * modpow(b, m - 2, m) % m;
}
//printf("%.10f\n", n);
typedef pair <ll, ll> P;
typedef pair <string, string> pp;
ll dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
struct edge { ll to, cost; };
struct Point {
	ll x, y;
};
bool operator<(const Point& a1, const Point& a2) {
	if (a1.x < a2.x) return true;
	if (a1.x > a2.x) return false;
	if (a1.y < a2.y) return true;
	return false;
}


vector<ll> spf;
void smallest_prime_factors(ll n) {
	spf.resize(n + 1); spf[1] = 1;
	for (int i = 2; i <= n; i++) {
		if (!spf[i]) {
			for (int j = i; j < n; j += i) { spf[j] = i; }
		}
	}
}
std::map<int, int> high_speed_prime_factor(int n) {
	std::map<int, int> res;
	while (n != 1) {
		res[spf[n]]++;
		n /= spf[n];
	}
	return res;
}

struct status {
	ll a; ll b; ll s;

	bool operator<(const status& rhs) const { return s < rhs.s; };
	bool operator>(const status& rhs) const { return s > rhs.s; };
};

int main() {
	srand((unsigned)time(NULL));
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	//cout << fixed << setprecision(15);

	ll n, ma = 0, sum = 0; cin >> n;
	vector<ll>l(n + 1);
	rep2(i, n) { cin >> l[i]; sum += l[i]; ma = max(ma, l[i]); }
	ll ans = INF;
	for (int i = ma; i < sum; i++) {//上限
		vector<ll>dp(n + 1);//i番目を切る時の最小値の最大値
		dp[0] = INF;
		rep2(j, n) {
			ll lsum = 0;
			for (int k = j; k > 0; k--) {
				lsum += l[k];
				if (lsum > i) { break; }
				else { dp[j] = max(dp[j], min(dp[k - 1], lsum)); }
			}
		}
		ans = min(ans, i - dp[n]);
	}
	cout << ans << endl;
	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3512
final_rank: 6

code_snippet: #include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define popcount(v) __builtin_popcountll(v)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
using namespace std;
using ll = long long;
template<class T> using rpriority_queue = priority_queue<T, vector<T>, greater<T>>;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=1LL<<60;
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T,class U,class V>void scan(tuple<T,U,V>& p){scan(get<0>(p));scan(get<1>(p));scan(get<2>(p));}
template<class T, size_t size> void scan(array<T, size>& a){ for(auto&& i : a) scan(i);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
ll updivide(ll a,ll b){return (a+b-1)/b;}
int msb(ll v){return 63-__builtin_clzll(v);}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}

int main(){
    INT(n);
    vector<int> a(n),sumv(n+1,0);
    rep(i,n){
        in(a[i]);
        sumv[i+1]=sumv[i]+a[i];
    }
    //最小値,最大値
    vector<set<pair<int,int>>> dp(n+1);
    dp[0].insert({INF,0});
    for(int i=0;i<n;i++){
        for(int j=i+1;j<=n;j++){
            if(i==0&&j==n)continue;
            int d=sumv[j]-sumv[i];
            for(auto p:dp[i]){
                dp[j].insert({min(p.first,d),max(p.second,d)});
            }
        }
    }
    int ans=INF;
    for(auto p:dp[n]){
        chmin(ans,abs(p.first-p.second));
    }
    out(ans);
}
accuracy: 1
time_ms: 450
memory_kb: 52688
final_rank: 15

code_snippet: // clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ld = long double;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vi = vector<int>;
using Vl = vector<ll>;
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define FORR(i, m, n) for(int i = (m)-1; i >= (n); --i)
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FOR(i, 1, n+1)
#define repr(i, n) FORR(i, n, 0)
#define repnr(i, n) FORR(i, n+1, 1)
#define all(s) (s).begin(), (s).end()
template <class T, class U>
bool chmax(T &a, const U b) { return a < b ? a = b, true : false; }
template <class T, class U>
bool chmin(T &a, const U b) { return b < a ? a = b, true : false; }
template <class T>
istream &operator>>(istream &is, vector<T> &v) { for (T &i : v) is >> i; return is; }
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &i : v) os << i << ' '; return os; }
template <class Head, class... Tail>
void co(Head&& head, Tail&&... tail) {
    if constexpr(sizeof...(tail)==0) cout<<head<<'\n'; else cout<<head<<' ',co(forward<Tail>(tail)...);
}
template <class Head, class... Tail>
void ce(Head&& head, Tail&&... tail) {
    if constexpr(sizeof...(tail)==0) cerr<<head<<'\n'; else cerr<<head<<' ',ce(forward<Tail>(tail)...);
}
template<typename T, typename... Args>
auto make_vector(T x, int arg, Args ...args) {
    if constexpr(sizeof...(args)==0) return vector<T>(arg, x); else return vector(arg,make_vector<T>(x, args...));
}
void sonic() { ios::sync_with_stdio(false); cin.tie(nullptr); }
void setp(const int n) { cout << fixed << setprecision(n); }
constexpr int64_t INF = 1000000000000000003;
constexpr int Inf = 1000000003;
constexpr int MOD = 1000000007;
constexpr int MOD_N = 998244353;
constexpr double EPS = 1e-7;
const double PI = acos(-1);

// clang-format on

int main(void) {
    int n;
    cin >> n;
    Vi l(n);
    cin >> l;
    int s = accumulate(all(l), 0);
    int m = *max_element(all(l));
    vector<int> cs(n + 1);
    repr(i, n) cs[i] = l[i] + cs[i + 1];

    int ans = Inf;
    FOR(i, m, s) {
        vector<int> dp(n + 1);
        dp[0] = Inf;
        rep(j, n) {
            repr(k, j + 1) {
                if (cs[k] - cs[j + 1] > i)
                    break;
                chmax(dp[j + 1], min(dp[k], cs[k] - cs[j + 1]));
            }
        }
        chmin(ans, i - dp[n]);
    }
    co(ans);

    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 3456
final_rank: 8

code_snippet: #include<cstdio>
#include<algorithm>
using namespace std;
int l[51],dp[51];
int main(void)
{
	int n,MIN,sum,lsum,i,j,k,ans,MAX2,a;
	scanf("%d",&n);
	lsum=0;
	MAX2=0;
	ans=50001;
	for(i=0;i<n;i++){
		scanf("%d",&l[i]);
		lsum+=l[i];
		MAX2=max(MAX2,l[i]);
	}
	for(i=MAX2;i<lsum;i++){
		for(j=0;j<n;j++){
			dp[j]=0;
		}
		sum=0;
		for(j=0;j<n;j++){
			sum+=l[j];
			if(sum>i){
				break;
			}
			dp[j]=sum;
		}
		for(j=0;j<n;j++){
			sum=0;
			for(k=j+1;k<n;k++){
				sum+=l[k];
				if(sum>i){
					break;
				}
				a=min(sum,dp[j]);
				dp[k]=max(a,dp[k]);
			}
		}
		ans=min(ans,i-dp[n-1]);
	}
	printf("%d\n",ans);
	return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 2764
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define rrep(i,n) for(int (i)=1;i<=(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define INF 1e18
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};

int n;
vector<int> l(55);
vector<int> sum(55);
vector<int> yokan;

bool check(int minlen, int maxlen) {
	vector<int> dp(55, 0);
	dp[0] = 1;
	rrep(i, n) {
		rep(j, i) {
			int nowlen = sum[i] - sum[j];
			if(minlen <= nowlen && nowlen <= maxlen && dp[j]) dp[i] = 1;
		}
	}
	return dp[n];
}

signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
	
	cin >> n;
	rep(i, n) {
		cin >> l[i];
		sum[i+1] = sum[i] + l[i];
	}
	rep(i, n+1) {
		REP(j, i+1, n+1) {
			if(i == 0 && j == n) continue;
			yokan.push_back(sum[j] - sum[i]);
		}
	}
	//for(auto &x : yokan) cout << x << " ";
	sort(all(yokan));
	int ans = sum[n];
	rep(i, yokan.size()) {
		REP(j, i+1, yokan.size()) {
			int minlen = yokan[i];
			int maxlen = yokan[j];
			if(check(minlen, maxlen)) chmin(ans, maxlen - minlen);
		}
	}
	cout << ans << endl;
	return 0;
}
accuracy: 1
time_ms: 2880
memory_kb: 3260
final_rank: 14

code_snippet: // #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ
int p[60];
int sum[60];
int dp[60][51000];
int main(){
	int a;scanf("%d",&a);
	// int sum=0;
	for(int i=0;i<a;i++)scanf("%d",p+i);
	for(int i=0;i<a;i++)sum[i+1]=sum[i]+p[i];
	for(int i=0;i<60;i++)for(int j=0;j<51000;j++)dp[i][j]=mod;
	for(int i=0;i<51000;i++)dp[0][i]=0;
	for(int i=0;i<a;i++){
		for(int j=1;j<51000;j++){
			if(dp[i][j]==mod)continue;
			for(int k=i+1;k<=a;k++){
				if(i==0&&k==a)continue;
				int val=sum[k]-sum[i];
				if(val<j)continue;
				dp[k][j]=min(dp[k][j],max(val,dp[i][j]));
			}
		}
	}
	int ret=mod;
	for(int i=0;i<51000;i++){
		// if(dp[a][i]<100)printf("%d: %d\n",i,dp[a][i]);
		ret=min(ret,dp[a][i]-i);
	}
	printf("%d\n",ret);
}
accuracy: 1
time_ms: 30
memory_kb: 14716
final_rank: 12

code_snippet: #include <iostream>
#include <vector>

constexpr int INF = 1 << 30;

void solve() {
    int n;
    std::cin >> n;

    std::vector<int> ls(n + 1);
    ls[0] = 0;
    for (int i = 1; i <= n; ++i) {
        int l;
        std::cin >> l;
        ls[i] = ls[i - 1] + l;
    }
    int lsum = ls.back();

    int ans = INF;
    for (int min = 0; min < lsum; ++min) {
        std::vector<int> lodp(n + 1, INF), tidp(n + 1, INF);
        lodp[0] = 0;
        for (int r = 1; r <= n; ++r) {
            for (int l = 0; l < r; ++l) {
                int len = ls[r] - ls[l];
                if (len < min) continue;
                lodp[r] = std::min(lodp[r], std::max(lodp[l], len));
                tidp[r] = std::min(tidp[r], std::max(tidp[l], len));
                if (len > min) continue;
                tidp[r] = std::min(tidp[r], std::max(lodp[l], len));
            }
        }
        ans = std::min(ans, tidp[n] - min);
    }

    std::cout << ans << std::endl;
}

int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 3220
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
signed main(){ 
  long long n,l[1000000],ans=100000000;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>l[i];
    if(i!=0){
      l[i]+=l[i-1];
  }
  }
  for(int bit =0;bit<(1<<n-1);bit++){
    vector<int> s;
    long long a=0,c=0;
    for(int i=0;i<n;i++){
      if(bit & (1<<i)){
	s.push_back(l[i]-a);
	a=l[i];
	if(i==n-1)
	  c++;
      }
    }
    int d[100000];
    if(s.size()==0){
      continue;
    }
    if(c==0){
      s.push_back(l[n-1]-a);
      //cout<<l[n-1]<<endl;
    }
    sort(s.begin(),s.end());
    /*/for(int i=0;i<s.size();i++){
      cout<<s[i]<<" ";
      }/*/
    //cout<<endl;
    if(ans>s[s.size()-1]-s[0]){
      ans=s[s.size()-1]-s[0];
      //cout<<s[s.size()-1]<<" "<<s[0]<<" "<<ans<<endl;
      /*/for(int i=0;i<s.size();i++){
	cout<<s[i]<<" ";
	}/*/
      //cout<<endl;
    }
  }
  cout<<ans<<endl;
  return(0);
}
accuracy: 0.38823529411764707
time_ms: 60
memory_kb: 3176
final_rank: 16

code_snippet: #include <bits/stdc++.h>
using namespace std;
signed main(){ 
  int n,l[10000],ans=100000000;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>l[i];
    if(i!=0){
      l[i]+=l[i-1];
  }
  }
  for(int bit =0;bit<(1<<n-1);bit++){
    vector<int> s;
    int a=0,c=0;
    for(int i=0;i<n;i++){
      if(bit & (1<<i)){
	s.push_back(l[i]-a);
	a=l[i];
	if(i==n-1)
	  c++;
      }
    }
    int d[100000];
    if(s.size()==0){
      continue;
    }
    if(c==0){
      s.push_back(l[n-1]-a);
      //cout<<l[n-1]<<endl;
    }
    sort(s.begin(),s.end());
    /*/for(int i=0;i<s.size();i++){
      cout<<s[i]<<" ";
      }/*/
    //cout<<endl;
    if(ans>s[s.size()-1]-s[0]){
      ans=s[s.size()-1]-s[0];
      //cout<<s[s.size()-1]<<" "<<s[0]<<" "<<ans<<endl;
      /*/for(int i=0;i<s.size();i++){
	cout<<s[i]<<" ";
	}/*/
      //cout<<endl;
    }
  }
  cout<<ans<<endl;
  return(0);
}
accuracy: 0.38823529411764707
time_ms: 60
memory_kb: 3176
final_rank: 16

code_snippet: #include<cstdio>
#include<algorithm>
using namespace std;
int l[51],dp[51];
int main(void)
{
	int n,MIN,sum,lsum,i,j,k,ans,MAX2,a;
	scanf("%d",&n);
	lsum=0;
	MAX2=0;
	ans=50001;
	for(i=0;i<n;i++){
		scanf("%d",&l[i]);
		lsum+=l[i];
		MAX2=max(MAX2,l[i]);
	}
	for(i=MAX2;i<lsum;i++){
		for(j=0;j<n;j++){
			dp[j]=0;
		}
		sum=0;
		for(j=0;j<n;j++){
			sum+=l[j];
			if(sum>i){
				break;
			}
			dp[j]=sum;
		}
		for(j=0;j<n;j++){
			sum=0;
			for(k=j+1;k<n;k++){
				sum+=l[k];
				if(sum>i){
					break;
				}
				a=min(sum,dp[j]);
				dp[k]=max(a,dp[k]);
			}
		}
		ans=min(ans,i-dp[n-1]);
	}
	printf("%d\n",ans);
	return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 2756
final_rank: 2

code_snippet: #include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 1e-8;

long long int N, M, K, H, W, L, R;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> N;
	vector<int>v(N + 1);
	for (int i = 1; i <= N; i++) {
		cin >> v[i];
		v[i] += v[i - 1];
	}
	L = -1;
	R = 50000;
	while (R - L > 1) {
		int mid = (R + L + 1) / 2;
		vector<vector<int>>dp(N + 1, vector<int>(25001));
		for (int i = 0; i <= 25000; i++) {
			dp[0][i] = 1;
		}
		for (int i = 1; i <= N; i++) {
			for (int j = max(0, i - (int)N + 1); j < i; j++) {
				for (int k = 1; k <= 25000; k++) {
					if (k + mid >= v[i] - v[j]&&k<=v[i]-v[j]) {
						dp[i][k] |= dp[j][k];
					}
				}
			}
		}
		int box = 0;
		for (int i = 1; i <= 25000; i++) {

			box |= dp[N][i];
		}
		if (box) {
			R = mid;
		}
		else {
			L = mid;
		}
	}
	cout << R << endl;
	return 0;
}
accuracy: 1
time_ms: 280
memory_kb: 7912
final_rank: 11

code_snippet: #include <bits/stdc++.h>

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT_ON(bit, i) (((bit >> i) & 1) > 0)
#define BIT_COUNT(bit) (__builtin_popcount(bit))

typedef long long LL;
template<typename T> std::vector<T> make_v(size_t a){return std::vector<T>(a);}
template<typename T,typename... Ts> auto make_v(size_t a, Ts... ts){ return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}    // C++14
template<typename T,typename V> typename std::enable_if<std::is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename std::enable_if<std::is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
void print() { std::cout << std::endl; }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { std::cout << head; if (sizeof...(tail) != 0) {std::cout << " ";} print(std::forward<Tail>(tail)...); }
template <class T> void print(std::vector<T> &v) {for (auto& a : v) { std::cout << a; if (&a != &v.back()) {std::cout << " ";} }std::cout << std::endl;}
template <class T> void print(std::vector<std::vector<T>> &vv) { for (auto& v : vv) { print(v); }}
inline bool inside(long long y, long long x, long long H, long long W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }
template<typename T> T &chmin(T &a, const T &b) { return a = std::min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = std::max(a, b); }

template<class T> inline std::vector<T> unique(std::vector<T> v) {
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    return v;
}
// 初項s, 交差dのn個の数列の和
long long sum_of_arithmetic_progression(long long s, long long d, long long n) {
    return n * (2 * s + (n - 1) * d) / 2;
}

// 2のべき乗数かどうか
bool is_power_of_two(long long x) {
    return !(x & (x - 1));
}

// aとbの最大公約数 O(log min(a, b))
long long gcd(long long a, long long b) {
    if (b == 0) { return a; }
    return gcd(b, a % b);
}

// 数列vの最大公約数 O(N log d)
long long gcd(std::vector<long long> &v) {
    long long ans = v[0];
    for (int i = 1; i < (int)v.size(); ++i) {
        ans = gcd(ans, v[i]);
    }
    return ans;
}

// aとbの最小公倍数 O(log min(a, b))
long long lcm(long long a, long long b) {
    long long g = gcd(a, b);
    return a / g * b;
}

const int INF = 1u << 30u;
const long long LINF = 1ull << 58u;
const double EPS = 1e-9;
const long double PI = acos(-1.0);
const std::vector<int> dy2 = {0, 1}, dx2 = {1, 0};  // 右，下
const std::vector<int> dy4 = {0, 1, 0, -1}, dx4 = {1, 0, -1, 0};    // 右，下，左，上
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };

using namespace std;


template<typename T>class CumulativeSum {
public:
    std::vector<T> memo1;               // 1次元用の累積和表
    std::vector<std::vector<T>> memo2;  // 2次元用の累積和表

    CumulativeSum() {}

    void build(const std::vector<T> &line) {
        this->memo1.assign(line.size() + 1, 0);

        for (int i = 0; i < line.size(); ++i) {
            this->memo1[i + 1] = this->memo1[i] + line[i];
        }
    }

    // 2次元の累積和表を作成
    void build(const std::vector<std::vector<T>> &board) {
        int height = board.size();
        int width = board[0].size();
        this->memo2.assign(height + 1, std::vector<T>(width + 1, 0));

        for (int y = 0; y < height; ++y) {
            for (int x = 0; x < width; ++x) {
                memo2[y + 1][x + 1] = board[y][x] + memo2[y + 1][x];
            }
            for (int x = 0; x < width; ++x) {
                memo2[y + 1][x + 1] += memo2[y][x + 1];
            }
        }
    }

    T sum(int left, int right) {
        return this->memo1[right] - this->memo1[left];
    }

    /*
    (y1, x1)から(y2, x2)の合計を返す．(y2, x2)は含まない
    座標はmemoを作成したboard準拠
    (ex, sum(0, 0, 2, 2)なら(0, 0), (0, 1), (1, 0), (1, 1)の合計を返す)
    */
    T sum(int y1, int x1, int y2, int x2) {
        return this->memo2[y2][x2] - this->memo2[y2][x1] - this->memo2[y1][x2] + this->memo2[y1][x1];
    }
};


CumulativeSum<LL> cs;
LL func(const int l, const int r, const vector<LL> &a, const LL maxi) {
    if (l == r) {
        return 0;
    }

    int N = r - l;
    vector<vector<long long>> dp(r + 1, vector<long long>(r + 1, LINF));
    for (int length = 1; length < N + 1; ++length) {
        for (int left = l; left < r; ++left) {
            int right = left + length;
            if (right > r) {
                continue;
            }

            auto sum = cs.sum(left, right);
            if (sum <= maxi) {
                chmin(dp[left][right], maxi - sum);
            }
            for (int m = left + 1; m < right; ++m) {
                chmin(dp[left][right], max(dp[left][m], dp[m][right]));
            }
        }
    }

    return dp[l][r];
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    LL N;
    cin >> N;
    auto L = make_v<LL>(N);
    FOR(i, 0, N) {
        cin >> L[i];
    }
    cs.build(L);
    LL maxi = MAX(L);

    LL ans = LINF;
    FOR(i, 0, N) {
        FOR(j, i + 1, N + 1) {

            LL len = cs.sum(i, j);
            if (len < maxi or j - i == N) {
                continue;
            }

            LL left = func(0, i, L, len);
            LL right = func(j, L.size(), L, len);
            chmin(ans, max(left, right));
        }
    }
    print(ans);

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3244
final_rank: 1