結果

問題 No.2854 -1 Subsequence
ユーザー sai
提出日時 2024-08-25 14:00:02
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 647 bytes
コンパイル時間 2,706 ms
コンパイル使用メモリ 251,944 KB
実行使用メモリ 7,936 KB
最終ジャッジ日時 2024-08-25 14:00:09
合計ジャッジ時間 4,632 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

void solve() {
  int N; std::cin >> N;
  std::vector<long long> A(N);
  for (auto &a : A) std::cin >> a;
  std::vector<long long> dp[2];
  const long long INF = (1LL<<60);
  for (int i = 0; i < 2; i++) dp[i].resize(N+1, -INF);
  dp[0][0] = 0;
  for (int i = 1; i <= N; i++) {
    dp[0][i] = std::max(dp[0][i-1], dp[1][i-1]+A[i-1]);
    dp[1][i] = std::max(dp[1][i-1], dp[0][i-1]-A[i-1]);
  }
  std::cout << std::max(dp[1][N], dp[0][N]) << std::endl;
}

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

  int testcases = 1;
  //std::cin >> testcases;
  for (;testcases--;) solve();

  return 0;
}
0