結果
問題 |
No.972 選び方のスコア
|
ユーザー |
|
提出日時 | 2020-01-25 15:38:34 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 995 bytes |
コンパイル時間 | 1,645 ms |
コンパイル使用メモリ | 172,604 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-14 04:05:48 |
合計ジャッジ時間 | 3,856 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 WA * 7 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll=long long; const ll INF=1001001001; const ll LINF=1001001001001001001; #define overload4(_1,_2,_3,_4,name,...) name #define rep1(n) for(ll i=0;i<(n);++i) #define rep2(i,n) for(ll i=0;i<(n);++i) #define rep3(i,a,b) for(ll i=(a);i<(b);++i) #define rep4(i,a,b,c) for(ll i=(a);i<(b);i+=(c)) #define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__) #define all(x) (x).begin(),(x).end() #define vec vector<ll> template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;} template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;} void solve(){ ll n;cin>>n; vec a(n); rep(i,n)cin>>a[i]; if(n<=2){ cout<<0<<endl; return; } sort(all(a)); ll ans=0; ll sum=0; rep(i,(n-1)/2){ sum+=a[i]+a[n-1-i]; chmax(ans,sum-a[i+1]*(i+1)*2); } cout<<ans<<endl; } int main(){ cin.tie(0); ios::sync_with_stdio(0); solve(); }