提交时间:2023-12-16 11:40:43

运行 ID: 116413

#include<bits/stdc++.h> #define int long long using namespace std; namespace Fast{ inline long long fr(){ register long long x = 0,f = 1; static char c = getchar(); while (c < '0' || c > '9'){ if (c == '-'){ f = -1; } c = getchar(); } while (c >= '0' && c <= '9'){ x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } return x * f; } inline void fw(long long x){ if (x == 0){ putchar('0'); return ; } if (x < 0){ x = -x; putchar('-'); } stack <char> s; while (x){ s.push((x % 10) + 48); x /= 10; } while (!s.empty()){ putchar(s.top()); s.pop(); } } inline void CCF(){ ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); } inline void DEBUG(){ puts("DEBUG"); } } using namespace Fast; int a[1005],dp[1005][2]; signed main(){ int n = fr(); for (int i = 1;i <= n;i++){ a[i] = fr(); } for (int i = 2;i <= n;i++){ dp[i][1] = -a[i]; for (int j = 1;j < i;j++){ dp[i][1] = max(dp[i][1],dp[j][1]); dp[i][0] = max(dp[i][0],dp[j][0]); if (a[i] > a[j]){ dp[i][0] = max(dp[i][0],dp[j][1] + a[i] - a[j]); } } } cout<<dp[n][0]; return 0; }