結果

問題 No.972 選び方のスコア
ユーザー tarattata1tarattata1
提出日時 2020-01-18 00:08:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,177 bytes
コンパイル時間 1,619 ms
コンパイル使用メモリ 82,036 KB
実行使用メモリ 5,812 KB
最終ジャッジ日時 2023-09-08 09:16:23
合計ジャッジ時間 4,351 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
5,764 KB
testcase_01 AC 45 ms
5,704 KB
testcase_02 AC 43 ms
5,552 KB
testcase_03 AC 22 ms
4,380 KB
testcase_04 AC 44 ms
5,748 KB
testcase_05 AC 44 ms
5,768 KB
testcase_06 AC 44 ms
5,704 KB
testcase_07 AC 34 ms
4,956 KB
testcase_08 AC 32 ms
5,804 KB
testcase_09 AC 31 ms
5,436 KB
testcase_10 AC 30 ms
5,740 KB
testcase_11 AC 32 ms
5,736 KB
testcase_12 AC 31 ms
5,740 KB
testcase_13 AC 32 ms
5,740 KB
testcase_14 AC 31 ms
5,700 KB
testcase_15 AC 33 ms
5,768 KB
testcase_16 AC 33 ms
5,700 KB
testcase_17 AC 33 ms
5,708 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,384 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 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=1; i<=n; i++) {
        if(i%2) {
            int p=i/2;
            ll ans0=s[n]-s[n-p]+s[p]-(ll)a[p]*(i-1);
            ans=MAX(ans,ans0);
        }
        else {
            int p=i/2;
            ll ans0=s[n]-s[n-(p-1)]+s[p+1]-(ll)(a[p-1]+a[p])*i/2;
            ans=MAX(ans,ans0);
        }
    }
    printf("%lld\n", ans);

    return 0;
}
0