結果
| 問題 | No.972 選び方のスコア |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-09-10 16:36:30 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 58 ms / 2,000 ms |
| コード長 | 774 bytes |
| コンパイル時間 | 3,419 ms |
| コンパイル使用メモリ | 278,808 KB |
| 実行使用メモリ | 6,784 KB |
| 最終ジャッジ日時 | 2025-09-10 16:36:37 |
| 合計ジャッジ時間 | 7,540 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2 << 17;
int n;
long a[maxn];
long s[maxn + 1];
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
for (int i = 0; i < n; i++) s[i + 1] = s[i] + a[i];
long ans = 0;
for (int i = 0; i < n; i++) {
int maxlen = min(i, n - i - 1);
auto check = [&](int idx) -> bool { return a[i - idx] + a[n - idx] >= 2 * a[i]; };
int tv = 0, fv = maxlen + 1;
while (fv - tv > 1) {
int mv = (fv + tv) / 2;
(check(mv) ? tv : fv) = mv;
}
ans = max(ans, s[n] - s[n - tv] + s[i] - s[i - tv] - a[i] * 2 * tv);
}
cout << ans << "\n";
}