D-吹_23暑假友谊赛No.2 (nowcoder.com)
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N = 1e6 + 50, INF = 0x3f3f3f3f;
int a[N], dp[N][2];
signed main () {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 2; i <= n; i++) {
dp[i][0] = max (dp[i - 1][0], dp[i - 1][1] + a[i - 1] - 1);
dp[i][1] = max (dp[i - 1][0] + a[i] - 1, dp[i - 1][1] + a[i] - a[i - 1]);
}
cout << max (dp[n][0], dp[n][1]) << endl;
return 0;
}
标签:int,多校,long,牛客,友谊赛,define
From: https://www.cnblogs.com/Lazyboyjdj/p/17603018.html