結果

問題 No.999 てん vs. ほむ
ユーザー IKyoproIKyopro
提出日時 2020-03-03 22:22:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 620 bytes
コンパイル時間 2,338 ms
コンパイル使用メモリ 195,856 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 00:39:10
合計ジャッジ時間 3,130 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 24 ms
5,376 KB
testcase_10 AC 8 ms
5,376 KB
testcase_11 AC 6 ms
5,376 KB
testcase_12 AC 11 ms
5,376 KB
testcase_13 AC 26 ms
5,376 KB
testcase_14 AC 27 ms
5,376 KB
testcase_15 AC 27 ms
5,376 KB
testcase_16 AC 26 ms
5,376 KB
testcase_17 AC 19 ms
5,376 KB
testcase_18 AC 19 ms
5,376 KB
testcase_19 AC 18 ms
5,376 KB
testcase_20 AC 19 ms
5,376 KB
testcase_21 AC 27 ms
5,376 KB
testcase_22 AC 24 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<ll> A(2*N);
    for(int i=0;i<2*N;i++) cin >> A[i];
    ll now = 0;
    for(int i=2*N-1;i>=0;i--){
        if(i%2) now += A[i];
        else now -= A[i];
    }
    ll ans = now;
    for(int i=0;i<2*N;i+=2){
        now += 2*A[i];
        now -= 2*A[i+1];
        ans = max(ans,now);
    }
    cout << ans << "\n";
}
0