結果

問題 No.2854 -1 Subsequence
ユーザー takumi152
提出日時 2024-08-25 13:55:51
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 720 bytes
コンパイル時間 855 ms
コンパイル使用メモリ 100,788 KB
最終ジャッジ日時 2025-02-24 01:01:08
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 998244353;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<ll> a(n);
  for (auto &x: a) cin >> x;

  vector<vector<ll>> dp(n + 1, vector<ll>(2, (ll) -1e18));
  dp[0][0] = 0;
  for (int i = 0; i < n; i++)
  {
    dp[i+1][0] = max(dp[i][0], dp[i][1] + a[i]);
    dp[i+1][1] = max(dp[i][1], dp[i][0] - a[i]);
  }

  ll ans = max(dp[n][0], dp[n][1]);

  cout << ans << endl;

  return 0;
}
0