結果

問題 No.999 てん vs. ほむ
ユーザー polyesterpolyester
提出日時 2020-02-29 00:40:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 919 bytes
コンパイル時間 823 ms
コンパイル使用メモリ 87,548 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 21:14:31
合計ジャッジ時間 2,854 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 4 ms
6,944 KB
testcase_09 AC 79 ms
6,940 KB
testcase_10 AC 25 ms
6,944 KB
testcase_11 AC 18 ms
6,940 KB
testcase_12 AC 36 ms
6,940 KB
testcase_13 AC 86 ms
6,944 KB
testcase_14 AC 85 ms
6,944 KB
testcase_15 AC 85 ms
6,940 KB
testcase_16 AC 86 ms
6,944 KB
testcase_17 AC 56 ms
6,944 KB
testcase_18 AC 55 ms
6,940 KB
testcase_19 AC 56 ms
6,940 KB
testcase_20 AC 55 ms
6,944 KB
testcase_21 AC 85 ms
6,940 KB
testcase_22 AC 82 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
using ll = long long;
int main(){
  int n;
  cin >> n;
  vector<int> a(2 * n);
  for (int i = 0; i < 2 * n; i++){
    cin >> a[i];
  }
  int left = 0, right = 2 * n - 1;

  vector<ll> sum1(n + 5, 0), sum2(n + 5, 0);

  for (int i = 0; i < n; i++){
    sum1[i + 1] = sum1[i] + a[2 * i] - a[2 * i + 1];
    //cout << sum1[i + 1] << " ";
  }
  //cout << endl;
  for (int i = 0; i < n; i++){
    sum2[i + 1] = sum2[i] + a[ 2 * n - 2 * i - 1] - a[ 2 * n - 2 * i - 2];
    //cout << sum2[i + 1] << " ";
  }
  //cout << endl;

  ll sum = sum1[n] + sum2[n];

  ll ans = 0;
  for (int i = 0; i <= n; i++){
    ans = max(ans, sum1[i] + sum2[n-i]);
  }
  //cout << endl << sum << " ";

  cout << ans << "\n";
  return 0;
}
0