結果

問題 No.837 Noelちゃんと星々2
ユーザー furafura
提出日時 2020-05-06 21:54:14
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 697 bytes
コンパイル時間 2,199 ms
コンパイル使用メモリ 203,872 KB
実行使用メモリ 4,788 KB
最終ジャッジ日時 2023-09-02 07:30:59
合計ジャッジ時間 3,933 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
4,572 KB
testcase_01 AC 25 ms
4,656 KB
testcase_02 AC 24 ms
4,624 KB
testcase_03 AC 24 ms
4,580 KB
testcase_04 AC 24 ms
4,604 KB
testcase_05 AC 24 ms
4,784 KB
testcase_06 AC 24 ms
4,788 KB
testcase_07 AC 24 ms
4,776 KB
testcase_08 AC 24 ms
4,612 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,384 KB
testcase_27 AC 1 ms
4,384 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,384 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

const long long INF=1LL<<61;

int main(){
	int n; scanf("%d",&n);
	vector<lint> a(n);
	rep(i,n) scanf("%lld",&a[i]);

	sort(a.begin(),a.end());

	if(a[0]==a[n-1]){
		puts("1");
		return 0;
	}

	vector<lint> sum(n+1);
	rep(i,n) sum[i+1]=sum[i]+a[i];

	lint ans=INF;
	for(int i=1;i<n;i++){
		lint cost=0,tar;

		tar=a[i/2];
		cost+=(i/2+1)*tar-sum[i/2+1];
		cost+=(sum[i]-sum[i/2+1])-(i-i/2-1)*tar;

		tar=a[i+(n-i)/2];
		cost+=((n-i)/2+1)*tar-(sum[i+(n-i)/2+1]-sum[i]);
		cost+=(sum[n]-sum[i+(n-i)/2+1])-(n-i-(n-i)/2-1)*tar;

		ans=min(ans,cost);
	}
	printf("%lld\n",ans);

	return 0;
}
0