#include <bits/stdc++.h> #define ll long long using namespace std; const int nmax =…
- User
#include <bits/stdc++.h> #define ll long long using namespace std; const int nmax = 1e6+1; ll a[nmax], f[2][nmax]; int n; int main() { ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); freopen("linegame.inp","r",stdin); freopen("linegame.out","w",stdout);
cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; f[0][1] = a[1]; f[1][1] = 0; for (int i = 2; i <= n; i++) { f[0][i] = max(f[0][i-1], f[1][i-1] + a[i]); f[1][i] = max(f[1][i-1], f[0][i-1] - a[i]); } cout << max(f[0][n],f[1][n]); return 0; } ý nghĩa câu lệnh - Assistant