You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
636 B

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n;
int w[N];
int f[N][3];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &w[i]);
//无法判定或肯定不合理的
memset(f, -0x3f, sizeof f);
//这些状态是合理的
for (int i = 0; i <= n; i++) f[i][0] = 0;
//开始进行状态转移
for (int i = 1; i <= n; ++i) {
f[i][0] = max(f[i - 1][0], f[i - 1][2]);
f[i][1] = max(f[i - 1][1], f[i - 1][0] - w[i]);
f[i][2] = f[i - 1][1] + w[i];
}
printf("%d\n", max(f[n][0], f[n][2]));
return 0;
}