結果
問題 |
No.2854 -1 Subsequence
|
ユーザー |
|
提出日時 | 2024-08-25 14:11:19 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,025 bytes |
コンパイル時間 | 830 ms |
コンパイル使用メモリ | 108,908 KB |
最終ジャッジ日時 | 2025-02-24 01:05:50 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 WA * 10 |
ソースコード
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <list> #include <set> #include <unordered_set> #include <map> #include <unordered_map> #include <cmath> #include <utility> #include <sstream> #include <queue> #include <queue> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int64_t best_if_last_pos = 0; int64_t best_if_last_neg = -1LL; int n; cin >> n; for (int i = 0; i < n; ++i) { int64_t val; cin >> val; int64_t next_neg = best_if_last_pos - val; if (best_if_last_neg != -1 && next_neg < best_if_last_neg) { next_neg = best_if_last_neg; } if (best_if_last_neg != -1) { int64_t next_pos = best_if_last_neg + val; if (next_pos > best_if_last_pos) { best_if_last_pos = next_pos; } } best_if_last_neg = next_neg; } int64_t ans = best_if_last_pos; if (best_if_last_neg != -1LL) { ans = max(best_if_last_neg, ans); } cout << ans << endl; return 0; }