結果

問題 No.972 選び方のスコア
ユーザー kotamanegikotamanegi
提出日時 2020-01-17 21:56:24
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 1,462 bytes
コンパイル時間 2,787 ms
コンパイル使用メモリ 134,744 KB
実行使用メモリ 6,372 KB
最終ジャッジ日時 2023-08-20 13:43:41
合計ジャッジ時間 5,141 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
6,160 KB
testcase_01 AC 58 ms
6,172 KB
testcase_02 AC 55 ms
6,160 KB
testcase_03 AC 28 ms
4,568 KB
testcase_04 AC 55 ms
6,116 KB
testcase_05 AC 56 ms
6,160 KB
testcase_06 AC 55 ms
6,172 KB
testcase_07 AC 44 ms
5,368 KB
testcase_08 AC 40 ms
6,132 KB
testcase_09 AC 39 ms
6,108 KB
testcase_10 AC 39 ms
6,184 KB
testcase_11 AC 40 ms
6,160 KB
testcase_12 AC 42 ms
6,264 KB
testcase_13 AC 40 ms
6,184 KB
testcase_14 AC 42 ms
6,160 KB
testcase_15 AC 47 ms
6,128 KB
testcase_16 AC 45 ms
6,188 KB
testcase_17 AC 46 ms
6,188 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 55 ms
6,372 KB
testcase_20 AC 55 ms
6,132 KB
testcase_21 AC 55 ms
6,128 KB
testcase_22 AC 53 ms
6,144 KB
testcase_23 AC 55 ms
6,164 KB
testcase_24 AC 56 ms
6,216 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,376 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 1 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:1:18: warning: '#pragma comment linker' ignored [-Wignored-pragmas]
#pragma comment (linker, "/STACK:256000000")
                 ^
1 warning generated.

ソースコード

diff #

#pragma comment (linker, "/STACK:256000000")
#define  _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()
void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(100);
}
#define int ll
ll summing[300000];
ll calc_sum(ll a, ll b) {
	return summing[b+1] - summing[a];
}
void solve() {
	int n;
	cin >> n;
	vector<ll> inputs;
	REP(i, n) {
		int a;
		cin >> a;
		inputs.pb(a);
	}
	sort(ALL(inputs));
	reverse(ALL(inputs));
	ll ans = 0;
	for (int i = 0; i < inputs.size(); ++i) {
		summing[i + 1] = summing[i] + inputs[i];
	}
	for (int i = inputs.size(); i+1 < inputs.size()+20; ++i) {
		summing[i + 1] = summing[i];
	}
	//mid point
	for (int i = 1; i+1 < (long long)inputs.size(); ++i) {
		ll bot = 0;
		ll top = min(i, (long long)inputs.size() - (i + 1LL));
		while (top - bot > 1) {
			ll mid = (top + bot) / 2LL;
			if (inputs[mid] + inputs[mid + i + 1] >= 2LL * inputs[i]) {
				bot = mid;
			}
			else {
				top = mid;
			}
		}
		ans = max(ans,(calc_sum(0, bot) + calc_sum(i + 1, bot + i + 1)) - inputs[i] * ((bot+1LL) * 2LL));
	}
	cout << ans << endl;
}

#undef int

int main() {
	init();
	solve();
}
0