結果

問題 No.972 選び方のスコア
ユーザー akakimidoriakakimidori
提出日時 2020-01-17 23:02:07
言語 Rust
(1.77.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 1,018 bytes
コンパイル時間 4,375 ms
コンパイル使用メモリ 147,364 KB
実行使用メモリ 7,276 KB
最終ジャッジ日時 2023-09-08 06:33:24
合計ジャッジ時間 4,046 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
7,276 KB
testcase_01 AC 61 ms
7,164 KB
testcase_02 AC 58 ms
7,112 KB
testcase_03 AC 29 ms
4,628 KB
testcase_04 AC 59 ms
7,248 KB
testcase_05 AC 59 ms
7,184 KB
testcase_06 AC 59 ms
7,260 KB
testcase_07 AC 45 ms
6,496 KB
testcase_08 AC 46 ms
7,192 KB
testcase_09 AC 44 ms
7,144 KB
testcase_10 AC 43 ms
7,256 KB
testcase_11 AC 43 ms
7,208 KB
testcase_12 AC 50 ms
7,248 KB
testcase_13 AC 48 ms
7,224 KB
testcase_14 AC 50 ms
7,264 KB
testcase_15 AC 57 ms
7,184 KB
testcase_16 AC 56 ms
7,264 KB
testcase_17 AC 56 ms
7,256 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 59 ms
7,264 KB
testcase_20 AC 59 ms
7,212 KB
testcase_21 AC 59 ms
7,272 KB
testcase_22 AC 57 ms
7,152 KB
testcase_23 AC 59 ms
7,204 KB
testcase_24 AC 59 ms
7,208 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,380 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 1 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let mut a: Vec<i64> = it.map(|s| s.parse().unwrap()).collect();
    a.sort();
    let mut sum = a.clone();
    sum.push(0);
    for i in (0..n).rev() {
        sum[i] += sum[i + 1];
    }
    let mut ans = 0;
    for mid in 1..n {
        let f = |x: usize| {
            let len = mid - x;
            sum[n - len] + sum[x] - sum[mid + 1] - (2 * len + 1) as i64 * a[mid]
        };
        let mut l = 0;
        let mut r = mid;
        while r - l > 10 {
            let ll = (2 * l + r) / 3;
            let rr = (l + 2 * r) / 3;
            if f(ll) <= f(rr) {
                l = ll;
            } else {
                r = rr;
            }
        }
        for i in l..r {
            ans = std::cmp::max(ans, f(i));
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}
0