結果

問題 No.972 選び方のスコア
ユーザー chocoruskchocorusk
提出日時 2020-01-17 21:47:39
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 987 bytes
コンパイル時間 891 ms
コンパイル使用メモリ 111,564 KB
実行使用メモリ 6,660 KB
最終ジャッジ日時 2023-09-08 02:18:10
合計ジャッジ時間 4,871 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 104 ms
6,660 KB
testcase_01 AC 108 ms
6,608 KB
testcase_02 AC 101 ms
6,376 KB
testcase_03 AC 49 ms
5,712 KB
testcase_04 AC 102 ms
6,388 KB
testcase_05 AC 100 ms
6,392 KB
testcase_06 AC 98 ms
6,400 KB
testcase_07 AC 79 ms
5,596 KB
testcase_08 AC 86 ms
6,400 KB
testcase_09 AC 86 ms
6,580 KB
testcase_10 AC 71 ms
6,360 KB
testcase_11 AC 79 ms
6,392 KB
testcase_12 AC 78 ms
6,404 KB
testcase_13 AC 96 ms
6,392 KB
testcase_14 AC 78 ms
6,356 KB
testcase_15 AC 93 ms
6,388 KB
testcase_16 AC 98 ms
6,408 KB
testcase_17 AC 94 ms
6,404 KB
testcase_18 AC 2 ms
5,348 KB
testcase_19 AC 94 ms
6,560 KB
testcase_20 AC 95 ms
6,376 KB
testcase_21 AC 92 ms
6,368 KB
testcase_22 AC 91 ms
6,560 KB
testcase_23 AC 94 ms
6,400 KB
testcase_24 AC 94 ms
6,396 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 2 ms
5,356 KB
testcase_29 AC 2 ms
5,380 KB
testcase_30 AC 2 ms
5,456 KB
testcase_31 AC 2 ms
5,408 KB
testcase_32 AC 2 ms
4,384 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n;
	cin>>n;
	ll a[200010];
	ll s[200020];
	s[0]=0;
	for(int i=0; i<n; i++){
		cin>>a[i];
	}
	sort(a, a+n);
	for(int i=0; i<n; i++) s[i+1]=s[i]+a[i];
	ll ans=0;
	for(int i=1; i<n-1; i++){
		if(a[n-1]-a[i]<=a[i]-a[i-1]) continue;
		int l=1, r=min(i, n-i-1)+1;
		while(r-l>1){
			int m=(l+r)/2;
			if(a[n-m]-a[i]>a[i]-a[i-m]) l=m;
			else r=m;
		}
		ans=max(ans, s[n]-s[n-l]+s[i]-s[i-l]-2*l*a[i]);
	}
	cout<<ans<<endl;
	return 0;
}
0