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.
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
const int N = 1e5 + 10;
|
|
|
|
|
const int INF = 0x3f3f3f3f;
|
|
|
|
|
int n;
|
|
|
|
|
int w[N];
|
|
|
|
|
int f[N][2];//考虑前i天的股市,第i天的手中股票状态为j(j=0 未持股,j=1 持股)
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
cin >> n;
|
|
|
|
|
for (int i = 1; i <= n; i++)cin >> w[i];
|
|
|
|
|
//base case
|
|
|
|
|
f[1][0] = 0;
|
|
|
|
|
f[1][1] = -w[1];
|
|
|
|
|
for (int i = 2; i <= n; i++) {
|
|
|
|
|
f[i][0] = max(f[i - 1][0], f[i - 1][1] + w[i]);
|
|
|
|
|
f[i][1] = max(f[i - 1][1], f[i - 1][0] - w[i]);
|
|
|
|
|
}
|
|
|
|
|
printf("%d\n", f[n][0]);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|