結果
| 問題 | No.972 選び方のスコア |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-01 00:13:50 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 41 ms / 2,000 ms |
| コード長 | 1,766 bytes |
| 記録 | |
| コンパイル時間 | 5,291 ms |
| コンパイル使用メモリ | 377,388 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2026-04-01 00:16:59 |
| 合計ジャッジ時間 | 13,931 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = unsigned __int128_t;
using mint = atcoder::static_modint<998244353>;
const int mod = 998244353;
#include <chrono>
mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1};
int dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};
template<class T>
bool chmin(T& a, const T& b){
if (b < a){
a = b;
return true;
}
else {
return false;
}
}
template<class T>
bool chmax(T& a, const T& b){
if (a < b){
a = b;
return true;
}
else {
return false;
}
}
void solve(){
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++){
cin >> a[i];
}
sort(a.begin(), a.end());
vector<ll> dp(n + 1);
for (int i = 0; i < n; i++){
dp[i + 1] = dp[i] + a[i];
}
ll ans = 0;
for (int i = 0; i < n; i++){
int now = a[i];
int l = 0, r = n + 1;
while(r - l > 1){
int mid = (r + l) / 2;
int x = i - mid, y = n - mid;
if (x < 0 || y <= i){
r = mid;
continue;
}
if (a[x] + a[y] >= 2 * now){
l = mid;
}
else {
r = mid;
}
}
chmax(ans, dp[i + 1] - dp[i - l] + dp[n] - dp[n - l] - 1LL * (2 * l + 1) * now);
}
cout << ans << '\n';
};
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
while(t--){
cout << fixed << setprecision(15);
solve();
}
}