結果

問題 No.999 てん vs. ほむ
ユーザー wonda_t_coffeewonda_t_coffee
提出日時 2020-02-28 22:44:10
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,234 bytes
コンパイル時間 744 ms
コンパイル使用メモリ 83,896 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 19:53:30
合計ジャッジ時間 2,464 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 WA -
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 25 ms
6,144 KB
testcase_10 AC 10 ms
5,376 KB
testcase_11 AC 7 ms
5,376 KB
testcase_12 AC 12 ms
5,376 KB
testcase_13 AC 27 ms
6,400 KB
testcase_14 AC 27 ms
6,272 KB
testcase_15 AC 27 ms
6,272 KB
testcase_16 AC 27 ms
6,400 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 27 ms
6,272 KB
testcase_22 AC 27 ms
6,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define REP(i,n)  for (int i = 0; i < (n); ++i)
#define SORT(a)   sort((a).begin(), (a).end());
#define UNIQ(a)   SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end());
#define FIND(a,x) find((a).begin(), (a).end(), (x)) != (a).end()

using namespace std;
using ll = long long;
using P = pair<int,int>;
using namespace std;

const int MOD = 1000000007; // 10^9 + 7

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N; cin >> N;
  vector<ll> a(2 * N);
  REP(i, 2 * N) cin >> a[i];
  vector<ll> left(N), right(N);

  ll lsum = 0;
  for(int i = 0; i < N; i++) {
    lsum += a[i * 2] - a[i * 2 + 1];
    left[i] = lsum;
  }

  ll rsum = 0;
  for(int i = N - 1; i >= 0; i--) {
    rsum += a[i * 2 + 1] - a[i * 2];
    right[i] = rsum;
  }
  reverse(right.begin(), right.end());

  ll ans = 0;
  for (int i = 0; i < N - 1; i++) {
    ans = max(ans, left[i] + right[N - i - 2]);
  }
  ans = max(ans, max(right[0], left[0]));
  cout << ans << endl;
}
0