結果

問題 No.609 Noelちゃんと星々
ユーザー むらため
提出日時 2019-01-18 06:07:10
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 620 bytes
コンパイル時間 1,811 ms
コンパイル使用メモリ 171,216 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-04 16:24:28
合計ジャッジ時間 3,759 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (n); i++)
int scan() {
  auto minus = false;
  int result = 0;
  while (true) {
    auto k = getchar_unlocked();
    if (k == '-')
      minus = true;
    else if (k < '0' || k > '9')
      break;
    else
      result = 10 * result + k - '0';
  }
  return result * (minus ? -1 : 1);
}
signed main() {
  int n = scan();
  vector<int> Y(n);
  REP(i, n) Y[i] = scan();
  sort(Y.begin(), Y.end());
  int mid = Y[n / 2];
  int ans = 0;
  REP(i, n) ans += abs(Y[i] - mid);
  printf("%lld\n", ans);
}
0