結果

問題 No.999 てん vs. ほむ
ユーザー a163236a163236
提出日時 2020-02-28 22:11:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 787 bytes
コンパイル時間 1,588 ms
コンパイル使用メモリ 164,768 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 19:02:56
合計ジャッジ時間 3,556 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 4 ms
6,944 KB
testcase_09 WA -
testcase_10 AC 23 ms
6,944 KB
testcase_11 AC 17 ms
6,940 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 87 ms
6,940 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 81 ms
6,944 KB
testcase_22 AC 78 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;



int main(void){

    ll N; cin>>N;
    vector<ll> A(2*N);
    for (int i = 0; i < 2 * N; ++i) {
        cin>>A[i];
    }

    vector<ll> SA(N), SA2(N);

    ll sum1=0;
    ll sum2 = 0;
    for (int i = 0; i < N; i++) {
        SA[i] += A[i*2] - A[i*2+1];
        SA2[i] += A[i*2+1] - A[i*2];
        sum1 += SA[i];
        sum2 += SA2[i];
    }

    for (int i = 0; i < N; ++i) {
        sum1 += SA[i];
    }

    ll ans = sum1;
    for (int i = 0; i < N; ++i) {
        sum1 = (sum1 - SA[i] - SA[i]) ;
        ans = max(ans, sum1);
    }

    for (int i = 0; i < N; ++i) {
        sum2 = (sum2 - SA2[i]-SA2[i]);
        ans = max(ans, sum2);
    }
    cout<<ans<<endl;
}
0