結果

問題 No.609 Noelちゃんと星々
ユーザー kyo1
提出日時 2021-01-13 09:33:24
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 518 bytes
コンパイル時間 2,012 ms
コンパイル使用メモリ 196,664 KB
最終ジャッジ日時 2025-01-17 17:14:31
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> Y(N);
  for (auto &&e : Y) {
    cin >> e;
  }
  sort(Y.begin(), Y.end());
  int64_t res = 0;
  if (N % 2 == 0) {
    int64_t a = 0, b = 0;
    for (auto &&e : Y) {
      a += abs(e - Y[N / 2]);
      b += abs(e - Y[N / 2 - 1]);
    }
    res = min(a, b);
  } else {
    for (auto &&e : Y) {
      res += abs(e - Y[N / 2]);
    }
  }
  cout << res << '\n';
  return 0;
}
0