結果

問題 No.972 選び方のスコア
ユーザー 👑 jupirojupiro
提出日時 2020-02-26 11:12:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 1,609 bytes
コンパイル時間 1,126 ms
コンパイル使用メモリ 117,184 KB
実行使用メモリ 6,300 KB
最終ジャッジ日時 2023-08-03 18:10:07
合計ジャッジ時間 3,992 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
6,300 KB
testcase_01 AC 57 ms
6,244 KB
testcase_02 AC 56 ms
5,944 KB
testcase_03 AC 28 ms
4,888 KB
testcase_04 AC 56 ms
6,216 KB
testcase_05 AC 56 ms
6,252 KB
testcase_06 AC 57 ms
6,220 KB
testcase_07 AC 43 ms
5,424 KB
testcase_08 AC 44 ms
6,216 KB
testcase_09 AC 43 ms
5,968 KB
testcase_10 AC 43 ms
6,252 KB
testcase_11 AC 44 ms
6,204 KB
testcase_12 AC 44 ms
6,160 KB
testcase_13 AC 44 ms
6,156 KB
testcase_14 AC 45 ms
6,204 KB
testcase_15 AC 45 ms
6,252 KB
testcase_16 AC 45 ms
6,196 KB
testcase_17 AC 45 ms
6,200 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 55 ms
6,212 KB
testcase_20 AC 54 ms
6,212 KB
testcase_21 AC 54 ms
6,248 KB
testcase_22 AC 54 ms
5,932 KB
testcase_23 AC 55 ms
6,252 KB
testcase_24 AC 55 ms
6,252 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,384 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long MAX = 5100000;
const long long INF = 1LL << 60;
const int inf = 1 << 28;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/

	ll N; scanf("%lld", &N);
	vector<ll> a(N); for (int i = 0; i < N; i++) scanf("%lld", &a[i]);
	sort(a.begin(), a.end());
	vector<ll> sum(N + 1); for (int i = 0; i < N; i++) sum[i + 1] = sum[i] + a[i];
	ll res = 0;
	for (ll i = 1; i < N - 1; i++) {
		ll left = 1;
		ll right = min(i, N - i - 1) + 1;
		while (right - left > 1) {
			ll mid = (left + right) >> 1;
			if (a[N - mid] + a[i - mid] >= a[i] * 2) left = mid;
			else right = mid;
		}
		ll tmp = sum[N] - sum[N - left] + sum[i] - sum[i - left] - a[i] * 2 * left;
		chmax(res, tmp);
	}
	cout << res << endl;
	/*
		おまじないを使ったらscanfとprintf関連注意!!!!!!!!!!!!
	*/
}
0