結果

問題 No.837 Noelちゃんと星々2
ユーザー kotatsugame
提出日時 2019-06-15 04:42:33
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 451 bytes
コンパイル時間 825 ms
コンパイル使用メモリ 69,712 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-11 14:21:14
合計ジャッジ時間 2,326 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 29
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    6 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<algorithm>
using namespace std;
int N;
long Y[1<<17],sum[1<<17];
main()
{
	cin>>N;
	for(int i=0;i<N;i++)cin>>Y[i];
	sort(Y,Y+N);
	if(Y[0]==Y[N-1])
	{
	    cout<<1<<endl;
	    return 0;
	}
	for(int i=0;i<N;i++)sum[i+1]=sum[i]+Y[i];
	long ans=9e18;
	for(int i=1;i<N;i++)
	{
		int a=i/2,b=(N+i)/2;
		ans=min(ans,sum[N]-sum[b]-Y[b]*(N-b)+Y[b]*(b-i)-sum[b]+sum[i]+sum[i]-sum[a]-Y[a]*(i-a)+Y[a]*a-sum[a]);
	}
	cout<<ans<<endl;
}
0