結果
問題 |
No.3268 As Seen in Toasters
|
ユーザー |
|
提出日時 | 2025-09-19 16:29:42 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,317 bytes |
コンパイル時間 | 3,023 ms |
コンパイル使用メモリ | 275,856 KB |
実行使用メモリ | 7,720 KB |
最終ジャッジ日時 | 2025-09-19 16:29:48 |
合計ジャッジ時間 | 5,746 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 39 WA * 2 |
ソースコード
#include <bits/stdc++.h> using namespace std; using int64 = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; if (!(cin >> N)) return 0; const long long INF = (1LL<<62); long long Pmin = INF, Pmax = -INF; // 非負の最小・最大 long long S = 0; // 負の絶対値合計 long long a1 = 0, a2 = 0; // 負の絶対値の最大・次点 int p = 0, m = 0; for (int i = 0; i < N; ++i) { long long x; cin >> x; if (x >= 0) { ++p; Pmin = min(Pmin, x); Pmax = max(Pmax, x); } else { ++m; long long a = -x; S += a; if (a >= a1) { a2 = a1; a1 = a; } else if (a > a2) { a2 = a; } } } long long S_edges = 0; if (m == 0) { // 非負のみ S_edges = Pmax - Pmin; // p>=2 前提だが p==1 のときは 0 になる } else if (p == 0) { // 負のみ S_edges = S; } else { // 両方あり S_edges = S + Pmax; } long long D = 0; if (m >= 2) D = max(D, a1 + a2); if (p >= 1) D = max(D, a1 + Pmax); if (p >= 2) D = max(D, Pmax - Pmin); long long ans = 2 * S_edges - D; cout << ans << '\n'; return 0; }