結果

問題 No.2854 -1 Subsequence
コンテスト
ユーザー わん
提出日時 2024-09-01 15:11:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 317 bytes
コンパイル時間 240 ms
コンパイル使用メモリ 82,896 KB
実行使用メモリ 104,908 KB
最終ジャッジ日時 2025-11-10 01:26:49
合計ジャッジ時間 4,462 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
A = list(map(int, input().split()))
INF = float('inf')
s = [0, -INF, -INF, -INF]
f = 0
for a in A:
  ns = s[:]
  if s[2] >= s[0]:f=1
  ns[0] = max(s[0], s[2])
  ns[1] = max(s[1], s[3])
  ns[2] = max(s[1]+a, s[3]+a)
  ns[3] = max(s[0]-a, s[2]-a)
  s = ns

ans = max(s) if f else max(s[1:])
print(ans)
0