結果

問題 No.999 てん vs. ほむ
ユーザー iqueue02iqueue02
提出日時 2020-02-28 22:32:17
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 698 bytes
コンパイル時間 1,539 ms
コンパイル使用メモリ 168,364 KB
実行使用メモリ 7,088 KB
最終ジャッジ日時 2023-08-03 21:13:09
合計ジャッジ時間 3,781 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 70 ms
6,508 KB
testcase_10 AC 23 ms
4,376 KB
testcase_11 AC 15 ms
4,384 KB
testcase_12 AC 32 ms
4,704 KB
testcase_13 AC 77 ms
6,904 KB
testcase_14 AC 77 ms
6,952 KB
testcase_15 AC 77 ms
7,020 KB
testcase_16 AC 77 ms
7,088 KB
testcase_17 AC 52 ms
6,616 KB
testcase_18 AC 51 ms
6,404 KB
testcase_19 AC 51 ms
6,668 KB
testcase_20 AC 51 ms
6,752 KB
testcase_21 AC 76 ms
6,700 KB
testcase_22 AC 73 ms
6,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int n;
  cin >> n;
  vector<int> a(2*n);
  rep(i,2*n) cin >> a[i];
  vector<ll> l(n,0), r(n,0);
  for (int i = 0; i < 2 * n; i += 2) {
    int x = a[i], y = a[i+1];
    l[i/2] = x - y;
    r[i/2] = y - x;
  }  
  vector<ll> lcum(n+1,0), rcum(n+1,0);
  for (int i = 0; i < n; i++) {
    lcum[i+1] = lcum[i] + l[i];
    rcum[n-i-1] = rcum[n-i] + r[n-i-1];
  }
  ll res = 0;
  for (int i = 0; i <= n; i++) {
    ll sum1 = lcum[i], sum2 = rcum[i];
    res = max(res, sum1 + sum2);
  }
  cout << res << endl;
  return 0;
}
0