#include int main() { using namespace std; int num; cin >> num; int* point = new int[num]; for (int i = 0; i < num; i++) cin >> point[i]; int** array = new int*[num]; for (int i = 0; i < num; i++) array[i] = new int[700000]; for (int i = 0; i < num; i++) for (int k = 0; k < 700000; k++) { if (i == 0) { if ((k+1) > point[i] || (k+1) == point[i]) array[i][k] = point[i]; else array[i][k] = 0; } else { if (k+1 > point[i]) { int a = point[i] + array[i-1][k - point[i]]; int b = array[i-1][k]; if (a > b) array[i][k] = a; else array[i][k] = b; } else if (k+1 == point[i]) { int a = point[i]; int b = array[i-1][k]; if (a > b) array[i][k] = a; else array[i][k] = b; } else array[i][k] = array[i-1][k]; } } cout << array[num-1][699999] << endl; return 0; }