結果

問題 No.972 選び方のスコア
ユーザー chocopuuchocopuu
提出日時 2020-01-17 23:00:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 103 ms / 2,000 ms
コード長 1,933 bytes
コンパイル時間 1,720 ms
コンパイル使用メモリ 170,796 KB
実行使用メモリ 6,476 KB
最終ジャッジ日時 2023-09-08 06:30:30
合計ジャッジ時間 5,533 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 103 ms
6,148 KB
testcase_01 AC 101 ms
6,200 KB
testcase_02 AC 96 ms
5,892 KB
testcase_03 AC 47 ms
4,704 KB
testcase_04 AC 93 ms
6,240 KB
testcase_05 AC 92 ms
6,192 KB
testcase_06 AC 93 ms
6,144 KB
testcase_07 AC 76 ms
5,452 KB
testcase_08 AC 84 ms
6,304 KB
testcase_09 AC 81 ms
6,024 KB
testcase_10 AC 80 ms
6,344 KB
testcase_11 AC 87 ms
6,296 KB
testcase_12 AC 88 ms
6,188 KB
testcase_13 AC 87 ms
6,148 KB
testcase_14 AC 87 ms
6,144 KB
testcase_15 AC 90 ms
6,372 KB
testcase_16 AC 92 ms
6,144 KB
testcase_17 AC 93 ms
6,280 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 92 ms
6,188 KB
testcase_20 AC 92 ms
6,476 KB
testcase_21 AC 91 ms
6,300 KB
testcase_22 AC 91 ms
5,944 KB
testcase_23 AC 91 ms
6,248 KB
testcase_24 AC 91 ms
6,200 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 1 ms
4,384 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
/*
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define int long long
#define REP(i,n) for(int i = 0;i < (int)(n);i++)
#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)
#define FOR(i,s,n) for(int i = s;i < (int)n;i++)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
#define ALL(a) a.begin(),a.end()
#define IN(a, x, b) (a<=x && x<b)
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a = b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a = b;return true;}return false;}
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void in(T&t){cin>>t;}
template<class T,class... Ts>inline void in(T&t,Ts&...ts){cin>>t;in(ts...);}
template<class T>inline void out(T t){cout<<t<<endl;}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout<<t<<" ";out(ts...);}
template<typename T=int>vector<T>mv(size_t a){return vector<T>(a);}
template<typename T=int,typename... Ts>auto mv(size_t a,Ts... ts){return vector<decltype(mv<T>(ts...))>(a,mv<T>(ts...));}
template<typename T,typename V>typename enable_if<is_class<T>::value==0>::type fill(T&t,const V&v){t=v;}
template<typename T,typename V>typename enable_if<is_class<T>::value!=0>::type fill(T&t,const V&v){for(auto &e:t)fill(e,v);}
constexpr long long INF = 1e18;

signed main(){
	int N;
	in(N);
	auto a = mv(N);
	in(a);
	sort(ALL(a));
	auto as = mv(N+1);
	REP(i,N)as[i+1] = as[i] + a[i];
	int ans = 0;
	REP(i,N){
		int ai = min(i,N-i-1);
		auto f =[&](int x)->bool{
			if(x == 0)return true;
			return (a[N-x]+a[i-x])>=a[i]*2;
		};
		int l = 0, r = ai + 1;
		while(r - l > 1){
			int c = (l + r) / 2;
			if(f(c)) l = c;
			else r = c;
		}
		int lo = as[i]-as[i-l];
		int hi = as[N]-as[N-l];
		int cost = lo-a[i]*l;
		cost += hi-a[i]*l;
		CHMAX(ans,cost);
	}
	out(ans);
}
0