結果
| 問題 |
No.972 選び方のスコア
|
| コンテスト | |
| ユーザー |
amaridekinai
|
| 提出日時 | 2020-01-17 22:30:24 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 668 bytes |
| コンパイル時間 | 2,066 ms |
| コンパイル使用メモリ | 171,924 KB |
| 実行使用メモリ | 6,528 KB |
| 最終ジャッジ日時 | 2024-06-25 22:00:10 |
| 合計ジャッジ時間 | 5,537 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 WA * 7 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
int n; cin >> n;
vector<ll>a(n);
for(int i = 0; i < n; i++){ cin >> a[i];}
sort(a.begin(),a.end());
vector<ll> sum(n);
sum[0] = a[0];
for(int i = 1; i < n; i++){
sum[i] = sum[i-1]+a[i];
}
ll ans = 0;
for(int i = 1; n-i > i; i++){ //どこを中央値とするか
ans = max(ans, sum[i-1]+sum[n-1]-sum[n-1-i]-2*i*a[i]);
}
for(int i = 2; n-i+1 > i; i++){
ll m = a[i]+a[i-1];
ans = max(ans, sum[i-2]+sum[n-1]-sum[n-i]-(i-1)*m);
}
cout << ans << endl;
return 0;
}
amaridekinai