結果

問題 No.972 選び方のスコア
ユーザー 沙耶花沙耶花
提出日時 2019-12-05 20:05:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 651 bytes
コンパイル時間 1,765 ms
コンパイル使用メモリ 172,116 KB
実行使用メモリ 6,656 KB
最終ジャッジ日時 2024-05-10 01:15:56
合計ジャッジ時間 5,420 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 99 ms
6,400 KB
testcase_01 AC 98 ms
6,400 KB
testcase_02 AC 94 ms
6,144 KB
testcase_03 AC 46 ms
5,376 KB
testcase_04 AC 89 ms
6,528 KB
testcase_05 AC 90 ms
6,400 KB
testcase_06 AC 91 ms
6,528 KB
testcase_07 AC 73 ms
5,632 KB
testcase_08 AC 78 ms
6,528 KB
testcase_09 AC 77 ms
6,528 KB
testcase_10 AC 80 ms
6,528 KB
testcase_11 AC 85 ms
6,528 KB
testcase_12 AC 85 ms
6,528 KB
testcase_13 AC 86 ms
6,656 KB
testcase_14 AC 86 ms
6,400 KB
testcase_15 AC 84 ms
6,528 KB
testcase_16 AC 86 ms
6,528 KB
testcase_17 AC 89 ms
6,400 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000



int main(){
	
	int N;
	cin>>N;
	
	vector<long long> a(N);
	for(int i=0;i<N;i++){
		cin>>a[i];
	}
	
	sort(a.begin(),a.end());
	
	vector<long long> S(N+1,0);
	for(int i=0;i<N;i++){
		S[i+1] = a[i];
		S[i+1] += S[i];
	}
	
	long long ans = 0;
	for(int i=1;i<N;i++){
		long long X = S[i];
		X += S[N] - S[N-(i-1)];
		ans = max(ans,X - (i*2-1)*a[i-1]);
	}
	
	for(int i=1;i<=N;i+=2){
		long long X = S[N] - S[N-i];
		X -= a[N-1-(i/2)] * N;
		ans = max(ans,X);
	}
	
	cout<<ans<<endl;


	return 0;
}
0