結果

問題 No.3185 Three Abs
ユーザー GOTKAKO
提出日時 2025-06-20 22:33:35
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 641 bytes
コンパイル時間 2,019 ms
コンパイル使用メモリ 195,752 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-06-20 22:33:43
合計ジャッジ時間 6,457 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

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

    int T; cin >> T;
    while(T--){
        int N; cin >> N;
        vector<long long> A(N);
        long long last = 0;
        for(auto &a : A) cin >> a,last += a;

        long long first = 0,answer = abs(last);
        long long minp = 0,maxp = 0;
        for(auto a : A){
            first += a,last -= a;
            minp = min(minp,first),maxp = max(maxp,first);
            answer = max(answer,abs(last)+max(abs(maxp)+abs(first-maxp),abs(minp)+abs(first-minp)));
        }
        cout << answer << "\n";
    }
}
0