Pagini recente » Cod sursa (job #789689) | Cod sursa (job #2990813) | Cod sursa (job #2376492) | Cod sursa (job #2051624) | Cod sursa (job #1417249)
#include <fstream>
#include <algorithm>
#include <math.h>
using namespace std;
int d[4][100005];
int main() {
int n, i, result, x, y;
ifstream f("oo.in");
ofstream g("oo.out");
f >> n;
result = x = y = i = 0;
for(i = 1; i <= n; i++) {
f >> d[0][i];
}
d[0][n + 1] = d[0][1];
d[1][2] = d[0][1] + d[0][2];
for(i = 3; i < n; i++) {
x = d[1][i - 1];
y = d[1][i - 3] + d[0][i - 1] + d[0][i];
d[1][i] = max(x, y);
}
result = max(result, d[1][n - 1]);
for(i = 3; i <= n; i++) {
x = d[2][i - 1];
y = d[2][i - 3] + d[0][i - 1] + d[0][i];
d[2][i] = max(x, y);
}
result = max(result, d[2][n - 0]);
for(i = 4; i <= n + 1; i++) {
x = d[3][i - 1];
y = d[3][i - 3] + d[0][i - 1] + d[0][i];
d[3][i] = max(x, y);
}
result = max(result, d[3][n + 1]);
g << result;
}