結果

問題 No.3185 Three Abs
ユーザー GGanari
提出日時 2025-07-04 15:30:27
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 973 bytes
コンパイル時間 2,026 ms
コンパイル使用メモリ 195,892 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-07-04 15:30:37
合計ジャッジ時間 8,854 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define INF 1000000001LL
#define LNF 1000000000000000001LL
#define MOD 1000000007LL
#define MAX 200000
#define long long long
#define all(x) x.begin(),x.end()
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t;
    cin >> t;
    while(t--)
    {
        long sum = 0;
        long res = 0;

        int n;
        cin >> n;
        vector<long> arr(n);
        for(int i = 0; i<n; i++)
        {
            cin >> arr[i];
            sum+=arr[i];
        }

        long mx = arr[0];
        long mn = arr[0];
        sum-=arr[0];
        long sum2 = arr[0];
        
        for(int i = 1; i<n-1; i++)
        {
            sum2+=arr[i];
            mx = max(mx,sum2);
            mn = min(mn,sum2);
            sum-=arr[i];
            res = max(abs(sum2-mx)+abs(mx)+abs(sum),res);
            res = max(abs(sum2-mn)+abs(mn)+abs(sum),res);
        }
        cout << res << "\n";
    }
    return 0;
}
0