結果

問題 No.999 てん vs. ほむ
ユーザー mikianaaamikianaaa
提出日時 2020-08-31 21:25:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 733 bytes
コンパイル時間 1,891 ms
コンパイル使用メモリ 166,948 KB
実行使用メモリ 4,808 KB
最終ジャッジ日時 2023-08-10 17:47:16
合計ジャッジ時間 2,907 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 24 ms
4,380 KB
testcase_10 AC 8 ms
4,380 KB
testcase_11 AC 6 ms
4,376 KB
testcase_12 AC 11 ms
4,380 KB
testcase_13 AC 25 ms
4,588 KB
testcase_14 AC 26 ms
4,580 KB
testcase_15 AC 25 ms
4,648 KB
testcase_16 AC 26 ms
4,808 KB
testcase_17 AC 19 ms
4,376 KB
testcase_18 AC 18 ms
4,432 KB
testcase_19 AC 19 ms
4,380 KB
testcase_20 AC 19 ms
4,652 KB
testcase_21 AC 25 ms
4,680 KB
testcase_22 AC 25 ms
4,568 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