結果
| 問題 | No.972 選び方のスコア |
| コンテスト | |
| ユーザー |
Fu_L
|
| 提出日時 | 2021-03-16 00:10:14 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 865 bytes |
| 記録 | |
| コンパイル時間 | 3,281 ms |
| コンパイル使用メモリ | 274,824 KB |
| 実行使用メモリ | 8,448 KB |
| 最終ジャッジ日時 | 2026-06-18 19:43:30 |
| 合計ジャッジ時間 | 6,131 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 WA * 7 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<ll,ll> P;
typedef modint1000000007 mint;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
const ll inf=1e18;
ll n,a[200005];
ll b[200005],c[200005];
ll ans;
int main(void){
cin.tie(0);
ios::sync_with_stdio(0);
cin>>n;
rep(i,0,n) cin>>a[i];
sort(a,a+n);
rep(i,0,n){
b[i+1]=b[i]+a[i];
c[i+1]=c[i]+a[n-1-i];
}
if(n<=2){
cout<<0<<endl;
return 0;
}
ans=(a[0]-a[1])+(a[n-1]-a[1]);
rep(i,4,n+1){
ll m;
if(i%2==0){
m=(a[n-i/2]+a[i/2-1]);
ans=max(ans,b[i/2]+c[i/2]-m*(i/2));
}else{
m=a[i/2];
ans=max(ans,b[i/2+1]+c[i/2]-m*i);
}
}
cout<<ans<<endl;
}
Fu_L