結果
| 問題 | No.609 Noelちゃんと星々 | 
| コンテスト | |
| ユーザー |  merom686 | 
| 提出日時 | 2017-12-09 00:08:13 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 21 ms / 2,000 ms | 
| コード長 | 507 bytes | 
| コンパイル時間 | 630 ms | 
| コンパイル使用メモリ | 79,320 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-29 20:36:13 | 
| 合計ジャッジ時間 | 1,910 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 25 | 
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> y(n);
    for (int i = 0; i < n; i++) {
        cin >> y[i];
    }
    sort(y.begin(), y.end());
    int x = y[n / 2];
    int64_t r = 0;
    for (int i = 0; i < n; i++) {
        r += abs(x - y[i]);
    }
    cout << r << endl;
    return 0;
}
            
            
            
        