結果

問題 No.999 てん vs. ほむ
ユーザー mikianaaamikianaaa
提出日時 2020-08-31 21:25:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 733 bytes
コンパイル時間 1,614 ms
コンパイル使用メモリ 167,764 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-28 11:13:27
合計ジャッジ時間 2,637 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 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 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 20 ms
5,376 KB
testcase_10 AC 8 ms
5,376 KB
testcase_11 AC 5 ms
5,376 KB
testcase_12 AC 10 ms
5,376 KB
testcase_13 AC 22 ms
5,376 KB
testcase_14 AC 24 ms
5,376 KB
testcase_15 AC 24 ms
5,376 KB
testcase_16 AC 24 ms
5,376 KB
testcase_17 AC 16 ms
5,376 KB
testcase_18 AC 15 ms
5,376 KB
testcase_19 AC 16 ms
5,376 KB
testcase_20 AC 16 ms
5,376 KB
testcase_21 AC 21 ms
5,376 KB
testcase_22 AC 21 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

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

    int N;
    cin >> N;
    vector<ll> left(N + 1, 0), right(N + 1, 0);
    ll sum = 0;
    rep(i, N) {
        ll a, b;
        cin >> a >> b;
        sum += (a + b);
        left[i + 1] = a;
        right[N - i] = b;
    }

    rep(i, N) {
        left[i + 1] += left[i];
        right[i + 1] += right[i];
    }

    ll homura = 0;

    rep(i, N+1) { homura = max(homura, left[i] + (N-i > 0 ? right[N - i] : 0)); }

    cout << 2 * homura - sum << endl;
}
0