結果

問題 No.972 選び方のスコア
ユーザー tarattata1tarattata1
提出日時 2020-01-18 00:51:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 1,640 bytes
コンパイル時間 2,140 ms
コンパイル使用メモリ 82,704 KB
実行使用メモリ 5,852 KB
最終ジャッジ日時 2023-09-08 10:34:02
合計ジャッジ時間 4,673 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
5,820 KB
testcase_01 AC 75 ms
5,852 KB
testcase_02 AC 71 ms
5,512 KB
testcase_03 AC 37 ms
4,376 KB
testcase_04 AC 74 ms
5,812 KB
testcase_05 AC 73 ms
5,840 KB
testcase_06 AC 73 ms
5,740 KB
testcase_07 AC 55 ms
4,964 KB
testcase_08 AC 62 ms
5,824 KB
testcase_09 AC 59 ms
5,516 KB
testcase_10 AC 57 ms
5,836 KB
testcase_11 AC 58 ms
5,824 KB
testcase_12 AC 58 ms
5,768 KB
testcase_13 AC 60 ms
5,780 KB
testcase_14 AC 58 ms
5,760 KB
testcase_15 AC 62 ms
5,820 KB
testcase_16 AC 62 ms
5,752 KB
testcase_17 AC 62 ms
5,736 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 73 ms
5,820 KB
testcase_20 AC 72 ms
5,836 KB
testcase_21 AC 72 ms
5,752 KB
testcase_22 AC 71 ms
5,564 KB
testcase_23 AC 72 ms
5,820 KB
testcase_24 AC 72 ms
5,800 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
 
using namespace std;


int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);
    vector<ll> a(n);
    vector<ll> s(n+1);
    int i;
    for(i=0; i<n; i++) {
        scanf("%lld", &a[i]);
    }
    sort(a.begin(), a.end());

    for(i=0; i<n; i++) {
        s[i+1]=s[i]+a[i];
    }
    ll ans=-INF;
    for(i=0; i<n; i++) {
        int k=MIN(i,n-i-1);
        if(k<0) continue;
        int l=0,r=k+1;
        while(r-l>1) {
            int m=(l+r)/2;
            if(a[n-m]-a[i]>a[i]-a[i-m]) {
                l=m;
            }
            else {
                r=m;
            }
        }
        ll ans0=s[n]-s[n-l]+s[i]-s[i-l]-(ll)a[i]*l*2;
        ans=MAX(ans,ans0);
    }
    for(i=0; i<n-1; i++) {
        int k=MIN(i,n-i-2);
        if(k<0) continue;
        int l=0,r=k+1;
        while(r-l>1) {
            int m=(l+r)/2;
            if(a[n-m]>a[i]+a[i+1]-a[i-m]) {
                l=m;
            }
            else {
                r=m;
            }
        }
        ll ans0=s[n]-s[n-l]+s[i]-s[i-l]-(ll)(a[i]+a[i+1])*(l+1);
        ans=MAX(ans,ans0);
    }
    printf("%lld\n", ans);

    return 0;
}
0