結果

問題 No.972 選び方のスコア
ユーザー 沙耶花沙耶花
提出日時 2020-01-13 13:05:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 864 bytes
コンパイル時間 2,327 ms
コンパイル使用メモリ 206,144 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-10 01:16:23
合計ジャッジ時間 9,229 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 228 ms
5,248 KB
testcase_01 WA -
testcase_02 AC 214 ms
5,376 KB
testcase_03 AC 176 ms
5,376 KB
testcase_04 AC 364 ms
5,376 KB
testcase_05 AC 358 ms
5,376 KB
testcase_06 AC 358 ms
5,376 KB
testcase_07 AC 172 ms
5,376 KB
testcase_08 AC 208 ms
5,376 KB
testcase_09 AC 201 ms
5,376 KB
testcase_10 AC 80 ms
5,376 KB
testcase_11 AC 86 ms
5,376 KB
testcase_12 AC 93 ms
5,376 KB
testcase_13 AC 94 ms
5,376 KB
testcase_14 AC 95 ms
5,376 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 218 ms
5,376 KB
testcase_20 AC 216 ms
5,376 KB
testcase_21 AC 215 ms
5,376 KB
testcase_22 AC 350 ms
5,376 KB
testcase_23 AC 214 ms
5,376 KB
testcase_24 AC 212 ms
5,376 KB
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 10000000.0

long long get_score(vector<long long> &a,int m){
	if(m>=a.size()||m<0)return 0;
	long long ret = 0;
	
	long long S = 0;
	
	for(int i=m-1;i>=0;i--){
		S += a[i];
		S += a[a.size()-1 - (m-1-i)];
		S -= 2*a[m];
		ret = max(ret,S);
	}
	
	return ret;
}


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());
	
	int left = 0;
	int right = N-1;
	
	while(right-left>2){
		int m1 = left + (right-left)/3;
		int m2 = m1 + (right-left)/3;
		
		if(get_score(a,m1)<get_score(a,m2))left = m1;
		else right = m2;
	}
	
	long long ans = 0;
	for(int i=left-1000;i<=right+1000;i++){
		ans = max(ans,get_score(a,i));
	}
	
	cout<<ans<<endl;
	
	
    return 0;
}
0