#include #include #define max(a, b) ((a) > (b) ? (a) : (b)) int main() { int n; scanf("%d", &n); int *v = (int *)malloc(sizeof(int) * (n + 1)); int *dp = (int *)malloc(sizeof(int) * (n + 1)); for (int i = 1; i != n + 1; i++) { scanf("%d", &v[i]); } dp[1] = v[1]; for (int i = 2; i != n + 1; i++) { dp[i] = max(dp[i - 1], dp[i - 2] + v[i]); } printf("%d\n", dp[n]); system("pause"); return 0; }