結果

問題 No.972 選び方のスコア
ユーザー 👑 kmjpkmjp
提出日時 2020-01-17 23:28:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,054 bytes
コンパイル時間 1,694 ms
コンパイル使用メモリ 168,644 KB
実行使用メモリ 5,200 KB
最終ジャッジ日時 2023-09-08 07:51:15
合計ジャッジ時間 4,587 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
4,936 KB
testcase_01 AC 41 ms
4,928 KB
testcase_02 AC 39 ms
4,872 KB
testcase_03 AC 20 ms
4,384 KB
testcase_04 AC 40 ms
5,076 KB
testcase_05 AC 38 ms
4,952 KB
testcase_06 AC 40 ms
4,932 KB
testcase_07 AC 31 ms
4,536 KB
testcase_08 AC 26 ms
4,936 KB
testcase_09 AC 25 ms
4,956 KB
testcase_10 AC 26 ms
4,928 KB
testcase_11 AC 29 ms
4,924 KB
testcase_12 AC 29 ms
4,924 KB
testcase_13 AC 29 ms
5,004 KB
testcase_14 AC 29 ms
4,948 KB
testcase_15 AC 30 ms
5,200 KB
testcase_16 AC 30 ms
4,928 KB
testcase_17 AC 30 ms
4,928 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 1 ms
4,380 KB
testcase_26 AC 2 ms
4,384 KB
testcase_27 AC 1 ms
4,384 KB
testcase_28 AC 1 ms
4,384 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,388 KB
testcase_31 AC 2 ms
4,384 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
ll A[202020];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>A[i];
	sort(A,A+N);
	ll ma=0;
	ll S0=0,S1=0;
	for(i=1;i*2+1<=N;i++) {
		S0+=A[i-1];
		S1+=A[N+1-i];
		ll pat=S1+S0-A[i-1]*(2*i-1);
		ma=max(ma,pat);
	}
	S0=0,S1=0;
	for(i=1;i*2<=N;i++) {
		S0+=A[i-1];
		S1+=A[N-i];
		ll pat=S0+S1-(A[N-i]+A[i-1])*i;
		ma=max(ma,pat);
	}
	cout<<ma<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0