結果

問題 No.972 選び方のスコア
ユーザー amotoma3amotoma3
提出日時 2020-01-25 16:28:54
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 1,279 bytes
コンパイル時間 1,679 ms
コンパイル使用メモリ 171,480 KB
実行使用メモリ 6,812 KB
最終ジャッジ日時 2023-10-12 04:36:55
合計ジャッジ時間 4,771 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
6,748 KB
testcase_01 AC 58 ms
6,540 KB
testcase_02 AC 55 ms
6,576 KB
testcase_03 AC 28 ms
4,928 KB
testcase_04 AC 57 ms
6,724 KB
testcase_05 AC 57 ms
6,544 KB
testcase_06 AC 57 ms
6,812 KB
testcase_07 AC 44 ms
6,368 KB
testcase_08 AC 43 ms
6,516 KB
testcase_09 AC 42 ms
6,704 KB
testcase_10 AC 42 ms
6,596 KB
testcase_11 AC 44 ms
6,704 KB
testcase_12 AC 44 ms
6,696 KB
testcase_13 AC 45 ms
6,628 KB
testcase_14 AC 44 ms
6,752 KB
testcase_15 AC 46 ms
6,536 KB
testcase_16 AC 45 ms
6,748 KB
testcase_17 AC 46 ms
6,660 KB
testcase_18 AC 2 ms
4,352 KB
testcase_19 AC 54 ms
6,652 KB
testcase_20 AC 54 ms
6,656 KB
testcase_21 AC 54 ms
6,804 KB
testcase_22 AC 55 ms
6,596 KB
testcase_23 AC 55 ms
6,732 KB
testcase_24 AC 55 ms
6,756 KB
testcase_25 AC 1 ms
4,352 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,352 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 1 ms
4,352 KB
testcase_31 AC 2 ms
4,352 KB
testcase_32 AC 2 ms
4,352 KB
testcase_33 AC 2 ms
4,352 KB
testcase_34 AC 2 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;}
vec s;
void init(vec &a){
    sort(all(a));
    s.push_back(0);
    for(ll x:a){
        s.push_back(x+s.back());
    }
}
ll query(ll from,ll to){
    return s[to]-s[from];
}
void solve(){
    /* (´~`) */
    ll n;cin>>n;
    vec a(n);
    rep(i,n)cin>>a[i];

    init(a);
    ll ans=0;
    rep(i,1,n-1){
        ll ng=min(i+1,n-i);
        ll ok=0;
        while(ng-ok>1){
            ll mid=(ng+ok)/2;
            if(a[i-mid]+a[n-mid]>2*a[i]) ok=mid;
            else ng=mid;
        }
        chmax(ans,query(i-ok,i)+query(n-ok,n)-2*ok*a[i]);
    }
    cout<<ans<<endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    solve();
}
0