結果
| 問題 |
No.972 選び方のスコア
|
| コンテスト | |
| ユーザー |
TAISA_
|
| 提出日時 | 2020-01-17 23:15:27 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,084 bytes |
| コンパイル時間 | 1,740 ms |
| コンパイル使用メモリ | 172,244 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-26 00:21:51 |
| 合計ジャッジ時間 | 3,830 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 WA * 7 |
ソースコード
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vll2 = vector<vector<ll>>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vll a(n + 1), sum(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a.begin() + 1, a.end());
for (int i = 1; i <= n; i++) {
sum[i] = sum[i - 1] + a[i];
}
ll res = 0;
for (int i = 1; i <= n; i++) {
ll s;
if (i % 2) {
s = sum[n] - sum[n - i / 2] + sum[i / 2] - (i - 1LL) * a[i / 2 + 1];
} else {
s = sum[n] - sum[n - i / 2 + 1] + sum[i / 2 - 1] -
(i - 2LL) * (a[i / 2] + a[i / 2 + 1]) / 2LL;
}
chmax(res, s);
}
cout << res << endl;
}
TAISA_