結果

問題 No.972 選び方のスコア
ユーザー HIR180HIR180
提出日時 2020-01-17 21:53:32
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 1,124 bytes
コンパイル時間 2,390 ms
コンパイル使用メモリ 187,876 KB
実行使用メモリ 6,828 KB
最終ジャッジ日時 2023-09-08 02:35:38
合計ジャッジ時間 5,509 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
6,556 KB
testcase_01 AC 58 ms
6,648 KB
testcase_02 AC 55 ms
6,396 KB
testcase_03 AC 28 ms
4,992 KB
testcase_04 AC 58 ms
6,552 KB
testcase_05 AC 58 ms
6,524 KB
testcase_06 AC 57 ms
6,540 KB
testcase_07 AC 42 ms
5,804 KB
testcase_08 AC 44 ms
6,604 KB
testcase_09 AC 42 ms
6,444 KB
testcase_10 AC 44 ms
6,600 KB
testcase_11 AC 45 ms
6,644 KB
testcase_12 AC 46 ms
6,600 KB
testcase_13 AC 46 ms
6,828 KB
testcase_14 AC 46 ms
6,828 KB
testcase_15 AC 46 ms
6,584 KB
testcase_16 AC 48 ms
6,556 KB
testcase_17 AC 47 ms
6,596 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 56 ms
6,528 KB
testcase_20 AC 56 ms
6,652 KB
testcase_21 AC 57 ms
6,540 KB
testcase_22 AC 54 ms
6,440 KB
testcase_23 AC 56 ms
6,628 KB
testcase_24 AC 56 ms
6,564 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n;
ll a[200005],rui[200005];
ll ans;
int main(){
	scanf("%d",&n);
	repn(i,n) scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	repn(i,n) rui[i] = rui[i-1]+a[i];
	for(int i=1;i<=n;i++){
		int cnt = min(i-1,n-i);
		int lb = 0,ub = cnt+1;
		while(ub-lb > 1){
			int mid = (lb+ub)/2;
			if(a[i-mid]+a[n+1-mid] >= 2LL*a[i]) lb = mid;
			else ub = mid;
		}
		ans = max(ans,rui[n]-rui[n-lb]+a[i]+rui[i-1]-rui[i-1-lb]-1LL*(lb+lb+1)*a[i]);
	}
	cout<<ans<<endl;
}
0