結果

問題 No.972 選び方のスコア
ユーザー 沙耶花沙耶花
提出日時 2019-12-04 18:25:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 708 bytes
コンパイル時間 1,559 ms
コンパイル使用メモリ 170,788 KB
実行使用メモリ 6,420 KB
最終ジャッジ日時 2023-08-22 19:34:02
合計ジャッジ時間 7,320 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
6,132 KB
testcase_01 AC 110 ms
6,256 KB
testcase_02 AC 104 ms
5,988 KB
testcase_03 AC 50 ms
4,552 KB
testcase_04 AC 102 ms
6,252 KB
testcase_05 AC 102 ms
6,260 KB
testcase_06 AC 103 ms
6,192 KB
testcase_07 AC 82 ms
5,532 KB
testcase_08 AC 92 ms
6,192 KB
testcase_09 AC 88 ms
5,984 KB
testcase_10 AC 91 ms
6,132 KB
testcase_11 AC 95 ms
6,128 KB
testcase_12 AC 96 ms
6,164 KB
testcase_13 AC 97 ms
6,184 KB
testcase_14 AC 97 ms
6,416 KB
testcase_15 AC 97 ms
6,264 KB
testcase_16 AC 99 ms
6,188 KB
testcase_17 AC 99 ms
6,420 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 98 ms
6,192 KB
testcase_20 AC 97 ms
6,236 KB
testcase_21 AC 97 ms
6,164 KB
testcase_22 AC 97 ms
5,864 KB
testcase_23 AC 97 ms
6,236 KB
testcase_24 AC 97 ms
6,188 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 1 ms
4,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-1;i++){
		int ok = 0;
		int ng = min(i,N-i-1)+1;
		
		while(ng-ok>1){
			int mid = (ok+ng)/2;
			if(a[i-mid]+a[N-mid]-2*a[i]>0)ok=mid;
			else ng=mid;
		}
		ans = max(ans,S[i]-S[i-ok]+S[N]-S[N-ok]-a[i]*(2*ok));
	}
	
	cout<<ans<<endl;


	return 0;
}
0