結果

問題 No.999 てん vs. ほむ
ユーザー rsk0315rsk0315
提出日時 2020-02-28 21:29:44
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 721 bytes
コンパイル時間 584 ms
コンパイル使用メモリ 57,808 KB
最終ジャッジ日時 2025-01-09 02:35:22
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:9:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |   scanf("%zu", &n);
      |   ~~~~~^~~~~~~~~~~
main.cpp:12:26: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |   for (auto& ai: a) scanf("%jd", &ai);
      |                     ~~~~~^~~~~~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <utility>
#include <vector>

int main() {
  size_t n;
  scanf("%zu", &n);

  std::vector<intmax_t> a(n+n);
  for (auto& ai: a) scanf("%jd", &ai);

  std::vector<intmax_t> left(n), right(n);
  for (size_t i = 0; i < n; ++i) {
    left[i] = a[i<<1] - a[i<<1|1];
    right[i] = -left[i];
  }

  {
    left.insert(left.begin(), 0);
    for (size_t i = 1; i <= n; ++i) left[i] += left[i-1];
    right.push_back(0);
    for (size_t i = n; i--;) right[i] += right[i+1];
  }

  intmax_t res = -1e15;
  for (size_t i = 0; i <= n; ++i) {
    // fprintf(stderr, "%jd?\n", left[i]+right[i]);
    res = std::max(res, left[i]+right[i]);
  }

  printf("%jd\n", res);
}
0