結果

問題 No.972 選び方のスコア
ユーザー furafura
提出日時 2020-07-25 16:10:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 561 bytes
コンパイル時間 2,177 ms
コンパイル使用メモリ 202,788 KB
実行使用メモリ 6,416 KB
最終ジャッジ日時 2023-09-09 14:58:57
合計ジャッジ時間 5,551 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
6,228 KB
testcase_01 AC 59 ms
6,284 KB
testcase_02 AC 55 ms
5,928 KB
testcase_03 AC 28 ms
4,720 KB
testcase_04 AC 59 ms
6,284 KB
testcase_05 AC 59 ms
6,284 KB
testcase_06 AC 57 ms
6,284 KB
testcase_07 AC 43 ms
5,376 KB
testcase_08 AC 45 ms
6,308 KB
testcase_09 AC 42 ms
5,972 KB
testcase_10 AC 47 ms
6,212 KB
testcase_11 AC 48 ms
6,212 KB
testcase_12 AC 48 ms
6,224 KB
testcase_13 AC 45 ms
6,096 KB
testcase_14 AC 45 ms
6,248 KB
testcase_15 AC 48 ms
6,292 KB
testcase_16 AC 47 ms
6,228 KB
testcase_17 AC 49 ms
6,416 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 54 ms
6,252 KB
testcase_20 AC 59 ms
6,148 KB
testcase_21 AC 56 ms
6,272 KB
testcase_22 AC 55 ms
5,928 KB
testcase_23 AC 58 ms
6,248 KB
testcase_24 AC 62 ms
6,208 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

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

using namespace std;
using lint=long long;

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

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

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

	lint ans=0;
	rep(i,n){
		int lo=0,hi=n;
		while(hi-lo>1){
			int mi=(lo+hi)/2;
			if(mi>0 && n-mi>i && i-mi>=0 && a[n-mi]+a[i-mi]-2*a[i]>=0) lo=mi;
 			else hi=mi;
		}
		ans=max(ans,cum[n]-cum[n-lo]+a[i]+cum[i]-cum[i-lo]-(2*lo+1)*a[i]);
	}
	printf("%lld\n",ans);

	return 0;
}
0