Created
December 11, 2017 13:11
-
-
Save mi6112ogit/91fce8a135515b29a854b7616cc02090 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
//#define int long long | |
#define FOR(i, j, k) for(int i = j; i < k; ++i) | |
#define rep(i, j) FOR(i, 0, j) | |
#define INF (1 << 30) | |
#define fi first | |
#define se second | |
typedef unsigned long long ull; | |
typedef pair<int, int> P; | |
typedef pair<P, int> Pi; | |
typedef pair<P, P> PP; | |
const int MOD = 1e9 + 7; | |
const int dy[]={0, 0, 1, -1}; | |
const int dx[]={1, -1, 0, 0}; | |
template <class T> void chmin(T& a, const T& b) { a = min(a, b); } | |
template <class T> void chmax(T& a, const T& b) { a = max(a, b); } | |
int dp[51][50001]; | |
int N, L[50]; | |
int sum[51]; | |
signed main() { | |
cin.tie(0); | |
ios::sync_with_stdio(false); | |
memset(dp, -1, sizeof(dp)); | |
dp[0][0] = INF; | |
cin >> N; | |
rep(i, N) cin >> L[i]; | |
sum[1] = L[0]; | |
FOR(i, 1, N) sum[i + 1] = sum[i] + L[i]; | |
rep(i, N) rep(j, sum[N]) { | |
if(dp[i][j] != -1) { | |
FOR(k, i, N) { | |
int latte = min(dp[i][j], sum[k + 1] - sum[i]); | |
int malta = max(j, sum[k + 1] - sum[i]); | |
chmax(dp[k + 1][malta], latte); | |
} | |
} | |
} | |
int res = INF; | |
rep(i, sum[N]) if(dp[N][i] != -1) { | |
chmin(res, i - dp[N][i]); | |
} | |
cout << res << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment