結果

問題 No.972 選び方のスコア
ユーザー utouto97utouto97
提出日時 2020-01-18 14:21:48
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 934 bytes
コンパイル時間 1,342 ms
コンパイル使用メモリ 148,632 KB
実行使用メモリ 6,472 KB
最終ジャッジ日時 2023-09-09 21:57:08
合計ジャッジ時間 6,003 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
6,472 KB
testcase_01 AC 110 ms
6,144 KB
testcase_02 AC 106 ms
6,032 KB
testcase_03 AC 51 ms
4,744 KB
testcase_04 AC 102 ms
6,168 KB
testcase_05 AC 103 ms
6,196 KB
testcase_06 AC 103 ms
6,228 KB
testcase_07 AC 83 ms
5,456 KB
testcase_08 AC 94 ms
6,200 KB
testcase_09 AC 91 ms
6,180 KB
testcase_10 AC 90 ms
6,268 KB
testcase_11 AC 95 ms
6,292 KB
testcase_12 AC 96 ms
6,144 KB
testcase_13 AC 96 ms
6,260 KB
testcase_14 AC 96 ms
6,196 KB
testcase_15 AC 97 ms
6,188 KB
testcase_16 AC 99 ms
6,148 KB
testcase_17 AC 98 ms
6,144 KB
testcase_18 AC 1 ms
4,384 KB
testcase_19 AC 98 ms
6,236 KB
testcase_20 AC 98 ms
6,148 KB
testcase_21 AC 98 ms
6,144 KB
testcase_22 AC 98 ms
6,064 KB
testcase_23 AC 98 ms
6,144 KB
testcase_24 AC 99 ms
6,296 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

/*
 */

using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int,int>;

int n;
int a[201010];

bool check(int x, int m){
  int tmp = (x == 0 ? 1 : a[n-x]+a[m-x]-2*a[m]);
  return tmp > 0;
}

signed main() {
  cin >> n;
  rep(i, 0, n) cin >> a[i];
  sort(a, a+n);
  vi sum(n+1);
  rep(i, 0, n) sum[i+1] = sum[i] + a[i];

  int ans = 0;
  rep(m, 0, n){
    int l = 0, r = min(m+1, n-m);
    while(r-l > 1){
      int mid = (l+r)/2;
      if(check(mid, m)) l = mid;
      else r = mid;
    }
    chmax(ans, sum[n]-sum[n-l]+sum[m]-sum[m-l]-2*a[m]*l);
  }

  cout << ans << endl;

  return 0;
}

0