結果

問題 No.972 選び方のスコア
ユーザー okok
提出日時 2020-01-17 23:10:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,495 bytes
コンパイル時間 814 ms
コンパイル使用メモリ 85,564 KB
実行使用メモリ 6,448 KB
最終ジャッジ日時 2023-09-08 06:52:56
合計ジャッジ時間 4,859 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 100 ms
6,140 KB
testcase_01 AC 100 ms
6,280 KB
testcase_02 AC 95 ms
6,032 KB
testcase_03 AC 49 ms
4,792 KB
testcase_04 AC 100 ms
6,208 KB
testcase_05 AC 99 ms
6,212 KB
testcase_06 AC 98 ms
6,220 KB
testcase_07 AC 75 ms
5,416 KB
testcase_08 AC 87 ms
6,104 KB
testcase_09 AC 84 ms
5,964 KB
testcase_10 AC 86 ms
6,116 KB
testcase_11 AC 86 ms
6,224 KB
testcase_12 AC 86 ms
6,152 KB
testcase_13 AC 87 ms
6,220 KB
testcase_14 AC 86 ms
6,116 KB
testcase_15 AC 88 ms
6,232 KB
testcase_16 AC 89 ms
6,116 KB
testcase_17 AC 88 ms
6,220 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,376 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<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}


int N;
vector<int> a, sum;

bool check(int m, int x){
	int y = x / 2;
	
	if(x%2) {
		if(m > min(y, N - y - 3)) {
			return false;
		} else {
			int a = sum[y] - sum[y - m];
			int b = sum[N] - sum[N - m];
			
			if(a <= b) return true;
			else return false;
		}
	} else {
		if(m > min(y, N - y - 2)) {
			return false;
		} else {
			int a = sum[y] - sum[y - m];
			int b = sum[N] - sum[N - m];
			
			if(a <= b) return true;
			else return false;
		}
	}
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int ans = 0;
	
	cin>>N;
	
	a.resize(N);
	sum.resize(N+1);
	
	for(int i = 0; i < N; i++){
		cin>>a[i];
		a[i] <<= 1;
	}
	
	sort(a.begin(), a.end());
	
	for(int i = 0; i < N; i++){
		sum[i+1] = a[i] + sum[i];
	}
	
	for(int i = 0; i < N * 2 - 1; i++){
		int l = 0, h = N * 100, m = 0;
		
		while(l + 1 < h){
			m = (l + h) >> 1;
			
			if(check(m, i)){
				l = m;
			} else {
				h = m;
			}
		}
			
		int temp = 0;
		
		int A = sum[i/2] - sum[i/2 - l];
		int B = sum[N] - sum[N - l];
		
		temp = A + B - l * (a[i/2] + a[(i + 1)/2]);
		
		ans = max(ans, temp);
		
	}
	
	cout<<ans/2<<endl;
	
	return 0;
}
0