結果
| 問題 |
No.2854 -1 Subsequence
|
| コンテスト | |
| ユーザー |
わん
|
| 提出日時 | 2024-09-01 15:11:06 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 116 ms / 2,000 ms |
| コード長 | 317 bytes |
| コンパイル時間 | 361 ms |
| コンパイル使用メモリ | 81,972 KB |
| 実行使用メモリ | 104,356 KB |
| 最終ジャッジ日時 | 2024-09-01 15:11:12 |
| 合計ジャッジ時間 | 5,052 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 40 |
ソースコード
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)
わん