結果

問題 No.999 てん vs. ほむ
ユーザー t98slider
提出日時 2022-12-23 15:34:04
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 430 bytes
コンパイル時間 1,621 ms
コンパイル使用メモリ 168,476 KB
実行使用メモリ 7,936 KB
最終ジャッジ日時 2024-11-18 04:06:45
合計ジャッジ時間 4,057 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
  int n;
  cin >> n;
  n *= 2;
  ll ans = -(1ll << 60);
  vector<ll> a(n), s0(n + 1), s1(n + 1);
  for(int i = 0; i < n; i++){
    cin >> a[i];
    s0[i + 1] = s0[i] + (i & 1 ? -a[i] : a[i]);
    s1[i + 1] = s1[i] + (i & 1 ? a[i] : -a[i]);
  }
  for(int i = 0; i <= n; i += 2){
    ans = max(ans, s0[i] + s1[n] - s1[i]);
  }
  cout << ans << '\n';
}
0