結果
問題 |
No.3185 Three Abs
|
ユーザー |
|
提出日時 | 2025-06-24 13:36:01 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 421 ms / 2,000 ms |
コード長 | 504 bytes |
コンパイル時間 | 1,875 ms |
コンパイル使用メモリ | 195,132 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-06-24 13:36:14 |
合計ジャッジ時間 | 12,560 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 30 |
ソースコード
#include <bits/stdc++.h> using namespace std; using i64 = long long; const int N = 200005; int n; i64 s[N]; int main() { int t; cin >> t; while (t--) { cin >> n; for (int i = 1; i <= n; i++) { cin >> s[i]; s[i] += s[i - 1]; } i64 ans = 0, mx = s[1], mn = s[1]; for (int j = 2; j < n; j++) { mx = max(mx, s[j - 1]); mn = min(mn, s[j - 1]); ans = max(ans, abs(s[n] - s[j]) + max(abs(s[j] - mx) + abs(mx), abs(s[j] - mn) + abs(mn))); } cout << ans << endl; } }