結果

問題 No.972 選び方のスコア
ユーザー nebukuro09nebukuro09
提出日時 2020-01-17 22:02:44
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 1,036 bytes
コンパイル時間 2,338 ms
コンパイル使用メモリ 109,292 KB
実行使用メモリ 13,832 KB
最終ジャッジ日時 2023-09-04 04:43:48
合計ジャッジ時間 5,047 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
13,192 KB
testcase_01 AC 96 ms
12,952 KB
testcase_02 AC 94 ms
13,292 KB
testcase_03 AC 46 ms
6,728 KB
testcase_04 AC 97 ms
13,376 KB
testcase_05 AC 96 ms
13,564 KB
testcase_06 AC 97 ms
13,360 KB
testcase_07 AC 73 ms
9,888 KB
testcase_08 AC 67 ms
13,480 KB
testcase_09 AC 65 ms
13,360 KB
testcase_10 AC 63 ms
13,340 KB
testcase_11 AC 67 ms
12,992 KB
testcase_12 AC 68 ms
13,048 KB
testcase_13 AC 72 ms
13,020 KB
testcase_14 AC 69 ms
13,180 KB
testcase_15 AC 74 ms
13,120 KB
testcase_16 AC 75 ms
13,132 KB
testcase_17 AC 76 ms
12,960 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 94 ms
13,716 KB
testcase_20 AC 95 ms
13,700 KB
testcase_21 AC 94 ms
13,800 KB
testcase_22 AC 93 ms
13,576 KB
testcase_23 AC 94 ms
13,700 KB
testcase_24 AC 94 ms
13,832 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,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!long).array;
    A.sort();

    auto B = new long[](N+1);
    foreach (i; 0..N) B[i+1] = B[i] + A[i];

    long sum(int l, int r) {
        if (r < l) return 0;
        return B[r+1] - B[l];
    }

    long calc(int l, int r, long v) {
        int hi = min(l, N - r - 1) + 1;
        int lo = 0;
        while (hi - lo > 1) {
            int mid = (hi + lo) / 2;
            if (A[l - mid] + A[N - mid] > v) {
                lo = mid;
            } else {
                hi = mid;
            }
        }
        return sum(l-lo, l-1) + sum(N-lo, N-1) - v * lo;
    }

    long ans = 0;

    foreach (i; 1..N-1) {
        ans = max(ans, calc(i, i, A[i] * 2));
        if (i < N - 2) ans = max(ans, calc(i, i + 1, A[i] + A[i+1]));
    }

    ans.writeln;
}
0