結果

問題 No.972 選び方のスコア
ユーザー drken1215drken1215
提出日時 2020-01-18 00:36:34
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 1,720 bytes
コンパイル時間 805 ms
コンパイル使用メモリ 76,580 KB
実行使用メモリ 6,324 KB
最終ジャッジ日時 2023-09-08 10:06:16
合計ジャッジ時間 5,259 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
6,180 KB
testcase_01 AC 112 ms
6,272 KB
testcase_02 AC 106 ms
6,028 KB
testcase_03 AC 52 ms
4,704 KB
testcase_04 AC 104 ms
6,176 KB
testcase_05 AC 104 ms
6,160 KB
testcase_06 AC 104 ms
6,320 KB
testcase_07 AC 83 ms
5,664 KB
testcase_08 AC 94 ms
6,272 KB
testcase_09 AC 90 ms
5,936 KB
testcase_10 AC 95 ms
6,208 KB
testcase_11 AC 99 ms
6,120 KB
testcase_12 AC 99 ms
6,324 KB
testcase_13 AC 101 ms
6,184 KB
testcase_14 AC 100 ms
6,252 KB
testcase_15 AC 99 ms
6,204 KB
testcase_16 AC 101 ms
6,272 KB
testcase_17 AC 101 ms
6,152 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 98 ms
6,292 KB
testcase_20 AC 99 ms
6,296 KB
testcase_21 AC 99 ms
6,176 KB
testcase_22 AC 100 ms
6,192 KB
testcase_23 AC 99 ms
6,216 KB
testcase_24 AC 97 ms
6,128 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,384 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }


int N;
vector<long long> a, s;

long long solve() {
    sort(a.begin(), a.end(), greater<long long>());
    s.assign(N+1, 0);
    for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i];

    //COUT(a);

    long long res = 0;
    for (int median = 1; median < N-1; ++median) {
        int mak = min(median, N-1-median);
        int left = 1, right = mak + 1;
        while (right - left > 1) {
            int mid = (left + right) / 2;
            if (a[mid-1] - a[median] >= a[median] - a[median+mid]) left = mid;
            else right = mid;
        }
        long long tmp = s[median+1+left] - s[median+1] + s[left];
        tmp -= a[median] * left * 2;

        //COUT("----------"); COUT(median); COUT(left); COUT(tmp);
        
        chmax(res, tmp);
    }
    return res;
}

int main() {
    while (cin >> N) {
        a.resize(N);
        for (int i = 0; i < N; ++i) cin >> a[i];
        cout << solve() << endl;
    }
}
0