結果
| 問題 |
No.972 選び方のスコア
|
| コンテスト | |
| ユーザー |
chocopuu
|
| 提出日時 | 2020-01-17 23:00:35 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 99 ms / 2,000 ms |
| コード長 | 1,933 bytes |
| コンパイル時間 | 1,671 ms |
| コンパイル使用メモリ | 173,832 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-25 23:44:54 |
| 合計ジャッジ時間 | 5,384 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
/*
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define int long long
#define REP(i,n) for(int i = 0;i < (int)(n);i++)
#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)
#define FOR(i,s,n) for(int i = s;i < (int)n;i++)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
#define ALL(a) a.begin(),a.end()
#define IN(a, x, b) (a<=x && x<b)
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a = b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a = b;return true;}return false;}
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void in(T&t){cin>>t;}
template<class T,class... Ts>inline void in(T&t,Ts&...ts){cin>>t;in(ts...);}
template<class T>inline void out(T t){cout<<t<<endl;}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout<<t<<" ";out(ts...);}
template<typename T=int>vector<T>mv(size_t a){return vector<T>(a);}
template<typename T=int,typename... Ts>auto mv(size_t a,Ts... ts){return vector<decltype(mv<T>(ts...))>(a,mv<T>(ts...));}
template<typename T,typename V>typename enable_if<is_class<T>::value==0>::type fill(T&t,const V&v){t=v;}
template<typename T,typename V>typename enable_if<is_class<T>::value!=0>::type fill(T&t,const V&v){for(auto &e:t)fill(e,v);}
constexpr long long INF = 1e18;
signed main(){
int N;
in(N);
auto a = mv(N);
in(a);
sort(ALL(a));
auto as = mv(N+1);
REP(i,N)as[i+1] = as[i] + a[i];
int ans = 0;
REP(i,N){
int ai = min(i,N-i-1);
auto f =[&](int x)->bool{
if(x == 0)return true;
return (a[N-x]+a[i-x])>=a[i]*2;
};
int l = 0, r = ai + 1;
while(r - l > 1){
int c = (l + r) / 2;
if(f(c)) l = c;
else r = c;
}
int lo = as[i]-as[i-l];
int hi = as[N]-as[N-l];
int cost = lo-a[i]*l;
cost += hi-a[i]*l;
CHMAX(ans,cost);
}
out(ans);
}
chocopuu