#include #include #include #include #include #include #include #include #include #include using namespace std; #define FOR(i,s,e) for (int i = int(s); i != int(e); i++) #define FORIT(i,c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++) #define ISEQ(c) (c).begin(), (c).end() int main(){ int N; cin >> N; int V[N]; FOR(i,0,N) cin >>V[i]; int mV[N]; mV[0] = V[0]; if(N == 1){ cout << mV[0] << endl; return 0; } mV[1] = max(V[0],V[1]); if(N == 2){ cout << mV[1] << endl; return 0; } FOR(i,2,N){ int max = -1; FOR(j,0,i-1){ if (V[i] + mV[j] > max) max = V[i] + mV[j]; } if (max < mV[i-1]) max = mV[i-1]; mV[i] = max; } cout << mV[N-1] << endl; return 0; }