define _CRT_SECURE_NO_WARNI NGS include iostream include vector includ

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <iomanip>
using namespace std;
vector <int> g, s;
int dp[101][101] = {0};
int ss (int i, int j) {
return s[j] - (i ? s[i-1] : 0);
}
int f (int i, int j) { //сумма на отрезке i, g
if (!dp[i][j]) {
if (i == j)
dp[i][j] = g[i];
//int a = g[i] + ss (i + 1, j) - f (i + 1, j);
//int b = g[j] + ss (i, j - 1) - f (i, j - 1);
else dp[i][j] = max (g[i] + ss (i + 1, j) - f (i + 1, j), g[j] + ss (i, j - 1) - f (i, j - 1));
}
return dp[i][j];
}
int main() {
freopen( "input.txt", "r", stdin);
freopen( "output.txt", "w", stdout);
int n; cin >> n;
g.resize (n); s.resize (n);
for (int i = 0; i < n; ++i) {
cin >> g[i];
s[i] = (i ? s[i-1] + g[i] : g[i]);
}
int k = f (0, n - 1) * 2 ;
if (k == s[n-1])
cout << 0 << endl;
else if (k < s[n-1])
cout << 2 << endl;
else cout << 1 << endl;
return 0;
}