結果

問題 No.972 選び方のスコア
ユーザー QCFiumQCFium
提出日時 2020-01-17 21:46:14
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 962 bytes
コンパイル時間 1,556 ms
コンパイル使用メモリ 168,488 KB
実行使用メモリ 6,024 KB
最終ジャッジ日時 2023-09-08 02:15:34
合計ジャッジ時間 5,400 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
5,680 KB
testcase_01 AC 62 ms
5,760 KB
testcase_02 AC 57 ms
5,568 KB
testcase_03 AC 31 ms
4,752 KB
testcase_04 AC 61 ms
5,888 KB
testcase_05 AC 59 ms
5,896 KB
testcase_06 AC 63 ms
5,844 KB
testcase_07 AC 49 ms
5,112 KB
testcase_08 AC 50 ms
5,828 KB
testcase_09 AC 48 ms
5,620 KB
testcase_10 AC 51 ms
5,756 KB
testcase_11 AC 52 ms
5,764 KB
testcase_12 AC 52 ms
5,688 KB
testcase_13 AC 54 ms
5,752 KB
testcase_14 AC 52 ms
5,684 KB
testcase_15 AC 54 ms
5,696 KB
testcase_16 AC 53 ms
5,752 KB
testcase_17 AC 54 ms
6,024 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 62 ms
5,856 KB
testcase_20 AC 63 ms
5,688 KB
testcase_21 AC 60 ms
5,752 KB
testcase_22 AC 60 ms
5,840 KB
testcase_23 AC 62 ms
5,820 KB
testcase_24 AC 64 ms
5,748 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,384 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	int a[n];
	for (auto &i : a) i = ri();
	std::sort(a, a + n);
	int64_t sum[n + 1];
	sum[0] = 0;
	for (int i = 0; i < n; i++) sum[i + 1] = sum[i] + a[i];
	int64_t res = 0;
	for (int i = 0; i < n; i++) {
		int l = -1, r = std::min(n - 1 - i, i);
		while (r - l > 1) {
			int m = l + ((r - l) >> 1);
			if (a[i] - a[i - 1 - m] > a[n - 1 - m] - a[i]) r = m;
			else l = m;
		}
		res = std::max(res, (sum[n] - sum[n - r]) + (sum[i] - sum[i - r]) - (int64_t) a[i] * 2 * r);
		// 
		if (i + 1 < n) {
			int l = -1, r = std::min(n - 2 - i, i);
			double center = (a[i] + a[i + 1]) / 2;
			while (r - l > 1) {
				int m = l + ((r - l) >> 1);
				if (a[i] - center > center - a[i]) r = m;
				else l = m;
			}
			res = std::max(res, (sum[n] - sum[n - r]) + (sum[i] - sum[i - r]) - (int64_t) (a[i] + a[i + 1]) * r);
		}
	}
	std::cout << res << std::endl;
	return 0;
}
0