結果

問題 No.972 選び方のスコア
ユーザー tnakao0123tnakao0123
提出日時 2020-01-19 01:03:48
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,300 bytes
コンパイル時間 810 ms
コンパイル使用メモリ 93,060 KB
実行使用メモリ 4,580 KB
最終ジャッジ日時 2023-09-10 23:57:39
合計ジャッジ時間 7,658 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 AC 27 ms
4,580 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 1 ms
4,376 KB
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 972.cc:  No.972 選び方のスコア - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef long long ll;
typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;

/* global variables */

int as[MAX_N];
ll ass[MAX_N + 1];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) scanf("%d", as + i);
  sort(as, as + n);

  for (int i = 0; i < n; i++) ass[i + 1] = ass[i] + as[i];

  ll maxsum = 0;

  for (int i = 1; i + 1 < n; i++) {
    int ai2 = as[i] * 2;
    int l0 = 0, l1 = min(i + 1, n - i);
    while (l0 + 1 < l1) {
      int l = (l0 + l1) / 2;
      if (as[i - l] + as[n - l] > ai2) l0 = l;
      else l1 = l;
    }

    ll sum =
      (ass[i] - ass[i - l0]) + (ass[n] - ass[n - l0]) - (ll)as[i] * (l0 * 2);
    if (maxsum < sum) maxsum = sum;
    //printf("i=%d, sum=%lld\n", i, sum);
  }

  printf("%lld\n", maxsum);
  return 0;
}
0