結果

問題 No.999 てん vs. ほむ
ユーザー kyo1
提出日時 2020-10-31 18:18:23
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 456 bytes
コンパイル時間 2,110 ms
コンパイル使用メモリ 194,660 KB
最終ジャッジ日時 2025-01-15 18:37:39
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 8 WA * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> A(2 * N);
  for (auto&& e : A) {
    cin >> e;
  }
  int64_t res = 0;
  int l = 0, r = 2 * N - 1;
  while (l < r) {
    if (A[l] - A[l + 1] < A[r] - A[r - 1]) {
      res += A[r] - A[r - 1];
      r -= 2;
    } else {
      res += A[l] - A[l + 1];
      l += 2;
    }
  }
  cout << res << '\n';
  return 0;
}
0