Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

#include <bits/stdc++.

h>
using namespace std;

int main() {
int n, i, sum = 0;
cin >> n;

int a[n];
int f[n][2];

for (int i = 0 ; i < n ; i++)


cin >> a[i];

for (i = 0; i < n - 1; i++) {


if (i == 0) {
f[0][0] = a[0] + a[1];
f[0][1] = a[0] * a[1];
}
else {
f[i][0] = max(f[i - 1][0] + a[i + 1], f[i - 1][1] + a[i + 1]);
f[i][1] = f[i - 1][0] - a[i] + a[i] * a[i + 1];
}
sum = max(f[i][0], f[i][1]);
}

cout << sum;


return 0;
}

You might also like