結果

問題 No.837 Noelちゃんと星々2
ユーザー leaf_1415
提出日時 2019-06-14 21:34:51
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 624 bytes
コンパイル時間 573 ms
コンパイル使用メモリ 59,304 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-11 14:12:06
合計ジャッジ時間 2,012 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#define llint long long

using namespace std;

llint n;
llint x[100005], sum[100005];

int main(void)
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> x[i];
	sort(x+1, x+n+1);
	for(int i = 1; i <= n; i++) sum[i] = sum[i-1] + x[i];
	
	if(x[1] == x[n]){
		cout << 1 << endl;
		return 0;
	}
	
	llint ans = 1e18;
	for(int i = 0; i <= n; i++){
		llint m1 = (1+i)/2, m2 = (i+1+n)/2;
		llint tmp = m1*x[m1] - sum[m1] + (sum[i]-sum[m1]) - (i-m1)*x[m1];
		tmp += (m2-i)*x[m2] - (sum[m2]-sum[i]) + (sum[n]-sum[m2]) - (n-m2)*x[m2];
		ans = min(ans, tmp);
	}
	cout << ans << endl;
	
	return 0;
}
0