結果

問題 No.999 てん vs. ほむ
ユーザー kibunakibuna
提出日時 2020-02-28 21:34:21
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 1,028 bytes
コンパイル時間 1,713 ms
コンパイル使用メモリ 165,528 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2024-04-21 18:03:13
合計ジャッジ時間 3,019 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 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 2 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 28 ms
6,272 KB
testcase_10 AC 9 ms
5,376 KB
testcase_11 AC 7 ms
5,376 KB
testcase_12 AC 14 ms
5,376 KB
testcase_13 AC 30 ms
6,528 KB
testcase_14 AC 30 ms
6,528 KB
testcase_15 AC 31 ms
6,528 KB
testcase_16 AC 30 ms
6,528 KB
testcase_17 AC 22 ms
6,272 KB
testcase_18 AC 20 ms
6,272 KB
testcase_19 AC 22 ms
6,272 KB
testcase_20 AC 22 ms
6,272 KB
testcase_21 AC 29 ms
6,400 KB
testcase_22 AC 28 ms
6,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n;
    cin >> n;
    vector<lint> a(2 * n);
    for (int i = 0; i < 2 * n; ++i) {
        cin >> a[i];
    }
    vector<lint> b(n, 0), c(n, 0);
    for (int i = 0; i < n; ++i) {
        b[i] = a[2 * i] - a[2 * i + 1];  // left - right
        c[i] = -a[2 * i] + a[2 * i + 1]; // right - left
    }
    for (int i = 1; i < n; ++i) {
        b[i] += b[i - 1];
        c[i] += c[i - 1];
    }
    lint ret = c[n - 1];
    // lint k   = (n + 1) / 2;
    // lint ret = tot - 2 * (a[n] - a[n - k]);
    for (int i = 0; i < n; ++i) {
        lint temp = c[n - 1] + 2 * b[i];
        chmax(ret, temp);
    }
    cout << ret << "\n";
    return 0;
}
0