結果

問題 No.999 てん vs. ほむ
ユーザー bonKotsubonKotsu
提出日時 2021-06-23 00:20:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 553 bytes
コンパイル時間 1,488 ms
コンパイル使用メモリ 167,724 KB
実行使用メモリ 7,268 KB
最終ジャッジ日時 2023-09-06 00:47:07
合計ジャッジ時間 4,922 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 71 ms
6,696 KB
testcase_10 AC 23 ms
4,376 KB
testcase_11 AC 15 ms
4,376 KB
testcase_12 AC 32 ms
4,744 KB
testcase_13 AC 78 ms
7,020 KB
testcase_14 AC 78 ms
6,960 KB
testcase_15 AC 78 ms
7,080 KB
testcase_16 AC 78 ms
7,268 KB
testcase_17 AC 52 ms
6,704 KB
testcase_18 AC 51 ms
6,488 KB
testcase_19 AC 52 ms
6,692 KB
testcase_20 AC 51 ms
6,848 KB
testcase_21 AC 76 ms
6,708 KB
testcase_22 AC 75 ms
6,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>

int main() {
  int n;
  cin >> n;
  vector<ll> a(2*n);
  rep(i,2*n) {
    cin >> a[i];
  }
  vector<ll> v(n);
  ll sum = 0;
  rep(i,n) {
    v[i] = a[2*i+1]-a[2*i];
    sum += v[i];
  }
  vector<ll> suml(n+1), sumr(n+1);
  rep(i,n) suml[i+1] = suml[i] + v[i];
  rep(i,n+1) sumr[i] = sum - suml[i];

  const ll INF = 1e18;
  ll ans = -INF;
  rep(i,n+1) ans = max(ans, sumr[i]-suml[i]);


  cout << ans << endl;
}
0