結果

問題 No.999 てん vs. ほむ
ユーザー ranarana
提出日時 2021-09-10 01:10:17
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 583 bytes
コンパイル時間 1,580 ms
コンパイル使用メモリ 93,072 KB
実行使用メモリ 6,348 KB
最終ジャッジ日時 2023-08-30 08:08:38
合計ジャッジ時間 4,069 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 77 ms
6,040 KB
testcase_10 AC 24 ms
4,376 KB
testcase_11 AC 17 ms
4,376 KB
testcase_12 AC 35 ms
4,400 KB
testcase_13 AC 84 ms
6,288 KB
testcase_14 AC 84 ms
6,348 KB
testcase_15 AC 84 ms
6,248 KB
testcase_16 AC 84 ms
6,280 KB
testcase_17 AC 55 ms
6,036 KB
testcase_18 AC 54 ms
6,060 KB
testcase_19 AC 55 ms
6,152 KB
testcase_20 AC 55 ms
6,036 KB
testcase_21 AC 83 ms
6,284 KB
testcase_22 AC 81 ms
5,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
    int n;
    cin >> n;

    vector<long long> a(2 * n);
    vector<long long> x(n+1, 0), y(n+1, 0);

    for (int i = 0; i < 2 * n; ++i) cin >> a[i];

    for (int i = 0; i < 2 * n; i += 2) x[i / 2 + 1] += x[i / 2] + a[i] - a[i+1];

    reverse(a.begin(), a.end());

    for (int i = 0; i < 2 * n; i += 2) y[i / 2 + 1] += y[i / 2] + a[i] - a[i+1];

    long long ans = 0;
    for (int i = 0; i <= n; ++i) {
        ans = max(ans, x[i] + y[n - i]);
    }

    cout << ans << endl;
}
0