結果

問題 No.837 Noelちゃんと星々2
ユーザー treeone
提出日時 2019-06-14 22:15:07
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 682 bytes
コンパイル時間 2,039 ms
コンパイル使用メモリ 197,912 KB
最終ジャッジ日時 2025-01-07 04:32:34
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 11 WA * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];
    sort(a.begin(), a.end());
    rep(i, 1, n){
        if(a[i] != a[0]) break;
        if(i == n - 1){
            cout << 1 << endl;
            return 0;
        }
    }
    int l = n / 4;
    int r = n - 1 - n / 4;
    int ans = 0;
    rep(i, 0, n){
        ans += min(abs(a[i] - a[l]), abs(a[i] - a[r]));
    }
    cout << ans << endl;
}
0